ComplianceRules

Category: Identity | Difficulty: Intermediate | Chapters: Compliance | Concept: Combining encrypted compliance checks with FHE.and()

Combines multiple compliance checks using FHE operations

Why this example

This example focuses on Combining encrypted compliance checks with FHE.and(). It is designed to be self-contained and easy to run locally.

Quick start

npm install
npm run test:mocked -- test/identity/FullFlow.test.ts

Dependencies

Deployment plan

Step
Contract
Args
Saves As

1

IdentityRegistry

-

registry

2

ComplianceRules

@registry, 1

complianceRules

3

CompliantERC20

"Compliant Token", "CPL", @complianceRules

token

Contract and test

Pitfalls to avoid

No pitfalls are highlighted in the tests for this example.

API Reference

Overview

Combines multiple compliance checks using FHE operations

Developer Notes

Example for fhEVM Examples - Identity Category

identityRegistry

Reference to the identity registry

owner

Owner/admin

pendingOwner

Pending owner for two-step ownership transfer

minKycLevel

Minimum KYC level required for compliance

authorizedCallers

Authorized callers that can request compliance checks for others

MinKycLevelUpdated

Emitted when the minimum KYC level requirement is updated

Parameters

Name
Type
Description

newLevel

uint8

The new minimum KYC level required for compliance

ComplianceChecked

Emitted when a compliance check is performed for a user

Parameters

Name
Type
Description

user

address

Address of the user whose compliance was checked

AuthorizedCallerUpdated

Emitted when a caller's authorization is updated

Parameters

Name
Type
Description

caller

address

Address being authorized or revoked

allowed

bool

Whether the caller is allowed

OwnershipTransferStarted

Emitted when ownership transfer is initiated

Parameters

Name
Type
Description

currentOwner

address

Current owner address

pendingOwner

address

Address that can accept ownership

OwnershipTransferred

Emitted when ownership transfer is completed

Parameters

Name
Type
Description

previousOwner

address

Previous owner address

newOwner

address

New owner address

OnlyOwner

Thrown when caller is not the contract owner

OnlyPendingOwner

Thrown when caller is not the pending owner

InvalidOwner

Thrown when new owner is the zero address

RegistryNotSet

Thrown when registry address is zero

CallerNotAuthorized

Thrown when caller is not authorized to check another user

AccessProhibited

Thrown when caller lacks permission for encrypted result

onlyOwner

onlyAuthorizedOrSelf

constructor

Initialize with identity registry reference

Parameters

Name
Type
Description

registry

address

Address of the IdentityRegistry contract

initialMinKycLevel

uint8

Initial minimum KYC level (default: 1)

setMinKycLevel

Update minimum KYC level

Parameters

Name
Type
Description

newLevel

uint8

New minimum level

setAuthorizedCaller

Allow or revoke a caller to check compliance for other users

Parameters

Name
Type
Description

caller

address

Address to update

allowed

bool

Whether the caller is allowed

transferOwnership

Initiate transfer of contract ownership

Parameters

Name
Type
Description

newOwner

address

Address that can accept ownership

acceptOwnership

Accept ownership transfer

checkCompliance

Check if user passes all compliance requirements

Combines: hasMinKycLevel AND isNotBlacklisted

Parameters

Name
Type
Description

user

address

Address to check

Return Values

Name
Type
Description

[0]

ebool

Encrypted boolean indicating compliance status Note: This function makes external calls to IdentityRegistry which computes and stores verification results. The combined result is stored locally for later retrieval.

checkComplianceWithCountry

Check compliance with additional country restriction

Parameters

Name
Type
Description

user

address

Address to check

allowedCountry

uint16

Country code that is allowed

Return Values

Name
Type
Description

[0]

ebool

Encrypted boolean indicating compliance status

getComplianceResult

Get the last compliance check result for a user

Call checkCompliance first to compute and store the result

Parameters

Name
Type
Description

user

address

Address to get result for

Return Values

Name
Type
Description

[0]

ebool

Encrypted boolean result

hasComplianceResult

Check if compliance result exists for user

Parameters

Name
Type
Description

user

address

Address to check

Return Values

Name
Type
Description

[0]

bool

Whether a cached result exists

Last updated