@chainlink/ace 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.foundry-version +1 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/auto-release-version.yml +107 -0
- package/.github/workflows/create-version-pr.yml +95 -0
- package/.github/workflows/forge-docs.yml +90 -0
- package/.github/workflows/forge-test.yml +59 -0
- package/.solhint-test.json +18 -0
- package/.solhint.json +16 -0
- package/.solhintignore +3 -0
- package/.solhintignore-test +2 -0
- package/Glossary.md +141 -0
- package/LICENSE +59 -0
- package/README.md +218 -0
- package/assets/chainlink-logo.svg +21 -0
- package/chainlink-ace-License-grants +2 -0
- package/foundry.toml +33 -0
- package/getting_started/GETTING_STARTED.md +477 -0
- package/getting_started/MyVault.sol +48 -0
- package/getting_started/advanced/.env.example +36 -0
- package/getting_started/advanced/GETTING_STARTED_ADVANCED.md +431 -0
- package/getting_started/advanced/SanctionsList.sol +25 -0
- package/getting_started/advanced/SanctionsPolicy.sol +58 -0
- package/package.json +41 -0
- package/packages/cross-chain-identity/README.md +148 -0
- package/packages/cross-chain-identity/docs/API_GUIDE.md +120 -0
- package/packages/cross-chain-identity/docs/API_REFERENCE.md +271 -0
- package/packages/cross-chain-identity/docs/CONCEPTS.md +253 -0
- package/packages/cross-chain-identity/docs/CREDENTIAL_FLOW.md +195 -0
- package/packages/cross-chain-identity/docs/SECURITY.md +70 -0
- package/packages/cross-chain-identity/src/CredentialRegistry.sol +245 -0
- package/packages/cross-chain-identity/src/CredentialRegistryIdentityValidator.sol +339 -0
- package/packages/cross-chain-identity/src/CredentialRegistryIdentityValidatorPolicy.sol +71 -0
- package/packages/cross-chain-identity/src/IdentityRegistry.sol +123 -0
- package/packages/cross-chain-identity/src/TrustedIssuerRegistry.sol +140 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialDataValidator.sol +30 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialRegistry.sol +170 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialRequirements.sol +192 -0
- package/packages/cross-chain-identity/src/interfaces/ICredentialValidator.sol +37 -0
- package/packages/cross-chain-identity/src/interfaces/IIdentityRegistry.sol +85 -0
- package/packages/cross-chain-identity/src/interfaces/IIdentityValidator.sol +18 -0
- package/packages/cross-chain-identity/src/interfaces/ITrustedIssuerRegistry.sol +61 -0
- package/packages/cross-chain-identity/test/CredentialRegistry.t.sol +220 -0
- package/packages/cross-chain-identity/test/CredentialRegistryIdentityValidator.t.sol +554 -0
- package/packages/cross-chain-identity/test/CredentialRegistryIdentityValidatorPolicy.t.sol +114 -0
- package/packages/cross-chain-identity/test/IdentityRegistry.t.sol +106 -0
- package/packages/cross-chain-identity/test/IdentityValidator.t.sol +969 -0
- package/packages/cross-chain-identity/test/TrustedIssuerRegistry.t.sol +123 -0
- package/packages/cross-chain-identity/test/helpers/BaseProxyTest.sol +112 -0
- package/packages/cross-chain-identity/test/helpers/MockCredentialDataValidator.sol +26 -0
- package/packages/cross-chain-identity/test/helpers/MockCredentialRegistryReverting.sol +131 -0
- package/packages/policy-management/README.md +197 -0
- package/packages/policy-management/docs/API_GUIDE.md +290 -0
- package/packages/policy-management/docs/API_REFERENCE.md +173 -0
- package/packages/policy-management/docs/CONCEPTS.md +156 -0
- package/packages/policy-management/docs/CUSTOM_POLICIES_TUTORIAL.md +195 -0
- package/packages/policy-management/docs/POLICY_ORDERING_GUIDE.md +91 -0
- package/packages/policy-management/docs/SECURITY.md +57 -0
- package/packages/policy-management/src/core/Policy.sol +124 -0
- package/packages/policy-management/src/core/PolicyEngine.sol +382 -0
- package/packages/policy-management/src/core/PolicyFactory.sol +92 -0
- package/packages/policy-management/src/core/PolicyProtected.sol +126 -0
- package/packages/policy-management/src/extractors/ComplianceTokenForceTransferExtractor.sol +57 -0
- package/packages/policy-management/src/extractors/ComplianceTokenFreezeUnfreezeExtractor.sol +54 -0
- package/packages/policy-management/src/extractors/ComplianceTokenMintBurnExtractor.sol +61 -0
- package/packages/policy-management/src/extractors/ERC20ApproveExtractor.sol +57 -0
- package/packages/policy-management/src/extractors/ERC20TransferExtractor.sol +62 -0
- package/packages/policy-management/src/extractors/ERC3643ForcedTransferExtractor.sol +56 -0
- package/packages/policy-management/src/extractors/ERC3643FreezeUnfreezeExtractor.sol +55 -0
- package/packages/policy-management/src/extractors/ERC3643MintBurnExtractor.sol +51 -0
- package/packages/policy-management/src/extractors/ERC3643SetAddressFrozenExtractor.sol +51 -0
- package/packages/policy-management/src/interfaces/IExtractor.sol +17 -0
- package/packages/policy-management/src/interfaces/IMapper.sol +17 -0
- package/packages/policy-management/src/interfaces/IPolicy.sol +61 -0
- package/packages/policy-management/src/interfaces/IPolicyEngine.sol +264 -0
- package/packages/policy-management/src/interfaces/IPolicyProtected.sol +48 -0
- package/packages/policy-management/src/policies/AllowPolicy.sol +104 -0
- package/packages/policy-management/src/policies/BypassPolicy.sol +90 -0
- package/packages/policy-management/src/policies/IntervalPolicy.sol +223 -0
- package/packages/policy-management/src/policies/MaxPolicy.sol +73 -0
- package/packages/policy-management/src/policies/OnlyAuthorizedSenderPolicy.sol +84 -0
- package/packages/policy-management/src/policies/OnlyOwnerPolicy.sol +35 -0
- package/packages/policy-management/src/policies/PausePolicy.sol +82 -0
- package/packages/policy-management/src/policies/README.md +632 -0
- package/packages/policy-management/src/policies/RejectPolicy.sol +89 -0
- package/packages/policy-management/src/policies/RoleBasedAccessControlPolicy.sol +162 -0
- package/packages/policy-management/src/policies/SecureMintPolicy.sol +271 -0
- package/packages/policy-management/src/policies/VolumePolicy.sol +133 -0
- package/packages/policy-management/src/policies/VolumeRatePolicy.sol +192 -0
- package/packages/policy-management/test/PolicyEngine.t.sol +368 -0
- package/packages/policy-management/test/PolicyFactory.t.sol +114 -0
- package/packages/policy-management/test/PolicyProtectedToken.t.sol +75 -0
- package/packages/policy-management/test/extractors/ComplianceTokenForceTransferExtractor.t.sol +59 -0
- package/packages/policy-management/test/extractors/ComplianceTokenFreezeUnfreezeExtractor.t.sol +74 -0
- package/packages/policy-management/test/extractors/ComplianceTokenMintBurnExtractor.t.sol +92 -0
- package/packages/policy-management/test/extractors/ERC20ApproveExtractor.t.sol +58 -0
- package/packages/policy-management/test/extractors/ERC3643ForcedTransferExtractor.t.sol +59 -0
- package/packages/policy-management/test/extractors/ERC3643FreezeUnfreezeExtractor.t.sol +74 -0
- package/packages/policy-management/test/extractors/ERC3643MintBurnExtractor.t.sol +73 -0
- package/packages/policy-management/test/extractors/ERC3643SetAddressFrozenExtractor.t.sol +56 -0
- package/packages/policy-management/test/helpers/BaseProxyTest.sol +75 -0
- package/packages/policy-management/test/helpers/CustomMapper.sol +26 -0
- package/packages/policy-management/test/helpers/DummyExtractor.sol +11 -0
- package/packages/policy-management/test/helpers/ExpectedParameterPolicy.sol +39 -0
- package/packages/policy-management/test/helpers/MockAggregatorV3.sol +51 -0
- package/packages/policy-management/test/helpers/MockToken.sol +66 -0
- package/packages/policy-management/test/helpers/MockTokenExtractor.sol +34 -0
- package/packages/policy-management/test/helpers/PolicyAlwaysAllowed.sol +45 -0
- package/packages/policy-management/test/helpers/PolicyAlwaysContinue.sol +23 -0
- package/packages/policy-management/test/helpers/PolicyAlwaysRejected.sol +23 -0
- package/packages/policy-management/test/helpers/PolicyFailingRun.sol +22 -0
- package/packages/policy-management/test/policies/AllowPolicy.t.sol +174 -0
- package/packages/policy-management/test/policies/BypassPolicy.t.sol +159 -0
- package/packages/policy-management/test/policies/IntervalPolicy.t.sol +307 -0
- package/packages/policy-management/test/policies/MaxPolicy.t.sol +54 -0
- package/packages/policy-management/test/policies/OnlyAuthorizedSenderPolicy.t.sol +95 -0
- package/packages/policy-management/test/policies/OnlyOwnerPolicy.t.sol +47 -0
- package/packages/policy-management/test/policies/PausePolicy.t.sol +75 -0
- package/packages/policy-management/test/policies/RejectPolicy.t.sol +182 -0
- package/packages/policy-management/test/policies/RoleBasedAccessControlPolicy.t.sol +223 -0
- package/packages/policy-management/test/policies/SecureMintPolicy.t.sol +442 -0
- package/packages/policy-management/test/policies/VolumePolicy.t.sol +158 -0
- package/packages/policy-management/test/policies/VolumeRatePolicy.t.sol +165 -0
- package/packages/tokens/erc-20/src/ComplianceTokenERC20.sol +345 -0
- package/packages/tokens/erc-20/src/ComplianceTokenStoreERC20.sol +29 -0
- package/packages/tokens/erc-20/test/ComplianceTokenERC20.t.sol +556 -0
- package/packages/tokens/erc-20/test/helpers/BaseProxyTest.sol +75 -0
- package/packages/tokens/erc-3643/README.md +24 -0
- package/packages/tokens/erc-3643/src/ComplianceTokenERC3643.sol +564 -0
- package/packages/tokens/erc-3643/src/ComplianceTokenStoreERC3643.sol +30 -0
- package/packages/tokens/erc-3643/test/ComplianceTokenERC3643.t.sol +815 -0
- package/packages/tokens/erc-3643/test/helpers/BaseProxyTest.sol +76 -0
- package/packages/tokens/erc-3643/test/helpers/ExpectedContextPolicy.sol +32 -0
- package/packages/vendor/erc-3643/compliance/modular/IModularCompliance.sol +220 -0
- package/packages/vendor/erc-3643/registry/interface/IClaimTopicsRegistry.sol +101 -0
- package/packages/vendor/erc-3643/registry/interface/IIdentityRegistry.sol +251 -0
- package/packages/vendor/erc-3643/registry/interface/IIdentityRegistryStorage.sol +191 -0
- package/packages/vendor/erc-3643/registry/interface/ITrustedIssuersRegistry.sol +161 -0
- package/packages/vendor/erc-3643/token/IToken.sol +457 -0
- package/packages/vendor/onchain-id/interface/IClaimIssuer.sol +53 -0
- package/packages/vendor/onchain-id/interface/IERC734.sol +110 -0
- package/packages/vendor/onchain-id/interface/IERC735.sol +105 -0
- package/packages/vendor/onchain-id/interface/IIdentity.sol +26 -0
- package/packages/vendor/onchain-id/interface/IImplementationAuthority.sol +21 -0
- package/remappings.txt +6 -0
- package/script/DeployComplianceTokenERC20.s.sol +191 -0
- package/script/DeployComplianceTokenERC3643.s.sol +208 -0
- package/script/DeploySimpleComplianceToken.s.sol +38 -0
- package/script/getting_started/DeployGettingStarted.s.sol +74 -0
- package/script/getting_started/advanced/DeployAdvancedGettingStarted.s.sol +332 -0
- package/script/getting_started/advanced/DeploySanctionsList.s.sol +26 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title IIdentityRegistry
|
|
6
|
+
* @notice The interface for managing identities within a registry. Identities are a bytes32 identifier known as
|
|
7
|
+
* the Cross-Chain ID (CCID), in which credentials and other information can be associated with. Multiple local
|
|
8
|
+
* blockchain accounts can be associated with a single CCID, but each account can only be associated with one CCID
|
|
9
|
+
* within this registry.
|
|
10
|
+
*/
|
|
11
|
+
interface IIdentityRegistry {
|
|
12
|
+
/// @notice Error emitted when an identity is already registered.
|
|
13
|
+
error IdentityAlreadyRegistered(bytes32 ccid, address account);
|
|
14
|
+
/// @notice Error emitted when an identity is not found.
|
|
15
|
+
error IdentityNotFound(bytes32 ccid, address account);
|
|
16
|
+
/// @notice Error emitted when an invalid identity configuration was attempted.
|
|
17
|
+
error InvalidIdentityConfiguration(bytes errorReason);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @notice Emitted when a new identity is registered.
|
|
21
|
+
* @param ccid The common cross-chain identifier of the identity.
|
|
22
|
+
* @param account The address of the account on this chain.
|
|
23
|
+
*/
|
|
24
|
+
event IdentityRegistered(bytes32 indexed ccid, address indexed account);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @notice Emitted when an identity is removed.
|
|
28
|
+
* @param ccid The common cross-chain identifier of the identity.
|
|
29
|
+
* @param account The address of the account on this chain.
|
|
30
|
+
*/
|
|
31
|
+
event IdentityRemoved(bytes32 indexed ccid, address indexed account);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @notice Registers a new local account address for a cross-chain identity.
|
|
35
|
+
*
|
|
36
|
+
* - MUST be access controlled to prevent unauthorized identity registration.
|
|
37
|
+
* - MUST revert with `IdentityAlreadyRegistered` if the ccid/account pair is already registered.
|
|
38
|
+
* - MUST emit the `IdentityRegistered` event.
|
|
39
|
+
*
|
|
40
|
+
* @param ccid The common cross-chain identifier of the identity.
|
|
41
|
+
* @param account The address of the account on this chain.
|
|
42
|
+
* @param context Additional information or authorization to perform the operation.
|
|
43
|
+
*/
|
|
44
|
+
function registerIdentity(bytes32 ccid, address account, bytes calldata context) external;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @notice Registers a list of new ccid/local account address pairs.
|
|
48
|
+
*
|
|
49
|
+
* - MUST be access controlled to prevent unauthorized identity registration.
|
|
50
|
+
* - MUST revert with `IdentityAlreadyRegistered` if one of the ccid/account pairs is already registered.
|
|
51
|
+
* - MUST emit the `IdentityRegistered` event for each ccid/account pair.
|
|
52
|
+
*
|
|
53
|
+
* @param ccids The list of common cross-chain identifiers for the identities.
|
|
54
|
+
* @param accounts The list of address for the identities on this chain.
|
|
55
|
+
* @param context Additional information or authorization to perform the operation.
|
|
56
|
+
*/
|
|
57
|
+
function registerIdentities(bytes32[] calldata ccids, address[] calldata accounts, bytes calldata context) external;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @notice Removes an identity.
|
|
61
|
+
*
|
|
62
|
+
* - MUST be access controlled to prevent unauthorized identity removal.
|
|
63
|
+
* - MUST revert with `IdentityNotFound` if the ccid/account pair is not registered.
|
|
64
|
+
* - MUST emit the `IdentityRemoved` event.
|
|
65
|
+
*
|
|
66
|
+
* @param ccid The common cross-chain identifier of the identity.
|
|
67
|
+
* @param account The address of the account on this chain.
|
|
68
|
+
* @param context Additional information or authorization to perform the operation.
|
|
69
|
+
*/
|
|
70
|
+
function removeIdentity(bytes32 ccid, address account, bytes calldata context) external;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @notice Gets the common cross-chain identifier of an identity.
|
|
74
|
+
* @param account The address of the account on this chain.
|
|
75
|
+
* @return the common cross-chain identifier of the identity.
|
|
76
|
+
*/
|
|
77
|
+
function getIdentity(address account) external view returns (bytes32);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @notice Gets the addresses of an account on this chain.
|
|
81
|
+
* @param ccid The common cross-chain identifier of the identity.
|
|
82
|
+
* @return the addresses of the accounts on this chain.
|
|
83
|
+
*/
|
|
84
|
+
function getAccounts(bytes32 ccid) external view returns (address[] memory);
|
|
85
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title IIdentityValidator
|
|
6
|
+
* @dev Interface for validating the account identity.
|
|
7
|
+
*/
|
|
8
|
+
interface IIdentityValidator {
|
|
9
|
+
/**
|
|
10
|
+
* @notice Validates the identity of an account.
|
|
11
|
+
* @dev This function MUST NOT revert. Use try-catch blocks around external calls and return
|
|
12
|
+
* false for any validation failures instead of allowing exceptions to propagate.
|
|
13
|
+
* @param account The account to validate.
|
|
14
|
+
* @param context Additional information or authorization to perform the operation.
|
|
15
|
+
* @return True if the account is a valid identity, false otherwise.
|
|
16
|
+
*/
|
|
17
|
+
function validate(address account, bytes calldata context) external view returns (bool);
|
|
18
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title ITrustedIssuerRegistry
|
|
6
|
+
* @dev Interface for managing trusted issuers in the system.
|
|
7
|
+
*/
|
|
8
|
+
interface ITrustedIssuerRegistry {
|
|
9
|
+
// ------------------------------------------------------------------------
|
|
10
|
+
// Events
|
|
11
|
+
// ------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @notice Emitted when a new trusted issuer is added.
|
|
15
|
+
* @param issuerIdHash The keccak256 hash of the issuerId string (indexed for filtering).
|
|
16
|
+
* @param issuerId The original issuerId string (human-readable, not indexed).
|
|
17
|
+
*/
|
|
18
|
+
event TrustedIssuerAdded(bytes32 indexed issuerIdHash, string issuerId);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @notice Emitted when a trusted issuer is removed.
|
|
22
|
+
* @param issuerIdHash The keccak256 hash of the issuerId string (indexed for filtering).
|
|
23
|
+
* @param issuerId The original issuerId string (human-readable, not indexed).
|
|
24
|
+
*/
|
|
25
|
+
event TrustedIssuerRemoved(bytes32 indexed issuerIdHash, string issuerId);
|
|
26
|
+
|
|
27
|
+
// ------------------------------------------------------------------------
|
|
28
|
+
// Logic
|
|
29
|
+
// ------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @notice Adds a new trusted issuer.
|
|
33
|
+
* @param issuerId The issuerId string of the issuer.
|
|
34
|
+
* @param context Additional information or authorization to perform the operation.
|
|
35
|
+
*/
|
|
36
|
+
function addTrustedIssuer(string memory issuerId, bytes calldata context) external;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @notice Removes a trusted issuer.
|
|
40
|
+
* @param issuerId The issuerId string of the issuer to remove.
|
|
41
|
+
* @param context Additional information or authorization to perform the operation.
|
|
42
|
+
*/
|
|
43
|
+
function removeTrustedIssuer(string memory issuerId, bytes calldata context) external;
|
|
44
|
+
|
|
45
|
+
// ------------------------------------------------------------------------
|
|
46
|
+
// View
|
|
47
|
+
// ------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @notice Checks if a issuerId corresponds to a trusted issuer.
|
|
51
|
+
* @param issuerId The issuerId string to check.
|
|
52
|
+
* @return True if the issuerId is trusted, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
function isTrustedIssuer(string memory issuerId) external view returns (bool);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @notice Returns the list of all trusted issuer identifiers (hashed).
|
|
58
|
+
* @return An array of keccak256 hashes of trusted issuerIds.
|
|
59
|
+
*/
|
|
60
|
+
function getTrustedIssuers() external view returns (bytes32[] memory);
|
|
61
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
pragma solidity 0.8.26;
|
|
3
|
+
|
|
4
|
+
import {IPolicyEngine} from "@chainlink/policy-management/interfaces/IPolicyEngine.sol";
|
|
5
|
+
import {ICredentialRegistry, CredentialRegistry} from "../src/CredentialRegistry.sol";
|
|
6
|
+
import {PolicyEngine} from "@chainlink/policy-management/core/PolicyEngine.sol";
|
|
7
|
+
import {BaseProxyTest} from "./helpers/BaseProxyTest.sol";
|
|
8
|
+
|
|
9
|
+
contract CredentialRegistryTest is BaseProxyTest {
|
|
10
|
+
bytes32 public constant CREDENTIAL_KYC = keccak256("common.kyc");
|
|
11
|
+
bytes32 public constant CREDENTIAL_ACCREDITED = keccak256("common.accredited");
|
|
12
|
+
|
|
13
|
+
PolicyEngine internal s_policyEngine;
|
|
14
|
+
CredentialRegistry internal s_credentialRegistry;
|
|
15
|
+
|
|
16
|
+
address internal s_owner;
|
|
17
|
+
|
|
18
|
+
function setUp() public {
|
|
19
|
+
s_owner = makeAddr("owner");
|
|
20
|
+
|
|
21
|
+
vm.startPrank(s_owner);
|
|
22
|
+
|
|
23
|
+
s_policyEngine = _deployPolicyEngine(true, address(this));
|
|
24
|
+
s_credentialRegistry = _deployCredentialRegistry(address(s_policyEngine));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function test_registerCredential_success() public {
|
|
28
|
+
bytes32 ccid = keccak256("account1");
|
|
29
|
+
|
|
30
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, 0, "", "");
|
|
31
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_ACCREDITED, 0, "", "");
|
|
32
|
+
|
|
33
|
+
bytes32[] memory creds = s_credentialRegistry.getCredentialTypes(ccid);
|
|
34
|
+
assert(creds.length == 2);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function test_registerCredentials_success() public {
|
|
38
|
+
bytes32 ccid = keccak256("account1");
|
|
39
|
+
|
|
40
|
+
bytes32[] memory credentialTypeIds = new bytes32[](2);
|
|
41
|
+
bytes[] memory credentialDatas = new bytes[](2);
|
|
42
|
+
|
|
43
|
+
credentialTypeIds[0] = CREDENTIAL_ACCREDITED;
|
|
44
|
+
credentialDatas[0] = "ACCREDITED";
|
|
45
|
+
|
|
46
|
+
credentialTypeIds[1] = CREDENTIAL_KYC;
|
|
47
|
+
credentialDatas[1] = "KYC";
|
|
48
|
+
|
|
49
|
+
s_credentialRegistry.registerCredentials(ccid, credentialTypeIds, 0, credentialDatas, "");
|
|
50
|
+
|
|
51
|
+
bytes32[] memory creds = s_credentialRegistry.getCredentialTypes(ccid);
|
|
52
|
+
assert(creds.length == 2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function test_registerCredential_expired_revert() public {
|
|
56
|
+
bytes32 ccid = keccak256("account1");
|
|
57
|
+
|
|
58
|
+
vm.expectPartialRevert(ICredentialRegistry.InvalidCredentialConfiguration.selector);
|
|
59
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, 1, "", "");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function test_removeCredential_success() public {
|
|
63
|
+
bytes32 ccid = keccak256("account1");
|
|
64
|
+
|
|
65
|
+
bytes32[] memory credentialTypeIds = new bytes32[](2);
|
|
66
|
+
bytes[] memory credentialDatas = new bytes[](2);
|
|
67
|
+
|
|
68
|
+
credentialTypeIds[0] = CREDENTIAL_ACCREDITED;
|
|
69
|
+
credentialDatas[0] = "ACCREDITED";
|
|
70
|
+
|
|
71
|
+
credentialTypeIds[1] = CREDENTIAL_KYC;
|
|
72
|
+
credentialDatas[1] = "KYC";
|
|
73
|
+
|
|
74
|
+
s_credentialRegistry.registerCredentials(ccid, credentialTypeIds, 0, credentialDatas, "");
|
|
75
|
+
|
|
76
|
+
bytes32[] memory creds = s_credentialRegistry.getCredentialTypes(ccid);
|
|
77
|
+
assert(creds.length == 2);
|
|
78
|
+
|
|
79
|
+
s_credentialRegistry.removeCredential(ccid, credentialTypeIds[0], "");
|
|
80
|
+
|
|
81
|
+
creds = s_credentialRegistry.getCredentialTypes(ccid);
|
|
82
|
+
assert(creds.length == 1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function test_removeCredential_notFound_failure() public {
|
|
86
|
+
bytes32 ccid = keccak256("account_not_defined");
|
|
87
|
+
|
|
88
|
+
bytes32[] memory creds = s_credentialRegistry.getCredentialTypes(ccid);
|
|
89
|
+
assert(creds.length == 0);
|
|
90
|
+
|
|
91
|
+
vm.expectRevert();
|
|
92
|
+
s_credentialRegistry.removeCredential(ccid, bytes32(0), "");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function test_getCredential_success() public {
|
|
96
|
+
bytes32 ccid = keccak256("account1");
|
|
97
|
+
bytes memory expectedData = bytes("data");
|
|
98
|
+
|
|
99
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, 0, expectedData, "");
|
|
100
|
+
|
|
101
|
+
bytes memory cred_data = s_credentialRegistry.getCredential(ccid, CREDENTIAL_KYC).credentialData;
|
|
102
|
+
|
|
103
|
+
assert(expectedData.length == cred_data.length);
|
|
104
|
+
for (uint256 i = 0; i < cred_data.length; i++) {
|
|
105
|
+
assert(cred_data[i] == expectedData[i]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function test_getCredential_notFound_failure() public {
|
|
110
|
+
bytes32 ccid = keccak256("account1");
|
|
111
|
+
bytes memory credentialData = bytes("data");
|
|
112
|
+
|
|
113
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, 0, credentialData, "");
|
|
114
|
+
|
|
115
|
+
vm.expectPartialRevert(ICredentialRegistry.CredentialNotFound.selector);
|
|
116
|
+
s_credentialRegistry.getCredential(ccid, CREDENTIAL_ACCREDITED);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function test_getCredentials_success() public {
|
|
120
|
+
bytes32 ccid = keccak256("account1");
|
|
121
|
+
|
|
122
|
+
bytes32[] memory credentialTypeIds = new bytes32[](2);
|
|
123
|
+
bytes[] memory credentialDatas = new bytes[](2);
|
|
124
|
+
|
|
125
|
+
credentialTypeIds[0] = CREDENTIAL_ACCREDITED;
|
|
126
|
+
credentialDatas[0] = "ACCREDITED";
|
|
127
|
+
|
|
128
|
+
credentialTypeIds[1] = CREDENTIAL_KYC;
|
|
129
|
+
credentialDatas[1] = "KYC";
|
|
130
|
+
|
|
131
|
+
s_credentialRegistry.registerCredentials(ccid, credentialTypeIds, 0, credentialDatas, "");
|
|
132
|
+
|
|
133
|
+
bytes32[] memory creds = s_credentialRegistry.getCredentialTypes(ccid);
|
|
134
|
+
assert(creds.length == 2);
|
|
135
|
+
|
|
136
|
+
ICredentialRegistry.Credential[] memory credentials = s_credentialRegistry.getCredentials(ccid, credentialTypeIds);
|
|
137
|
+
|
|
138
|
+
assert(credentials.length == 2);
|
|
139
|
+
assert(keccak256(credentials[0].credentialData) == keccak256(bytes("ACCREDITED")));
|
|
140
|
+
assert(keccak256(credentials[1].credentialData) == keccak256(bytes("KYC")));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function test_getCredentials_notFound_failure() public {
|
|
144
|
+
bytes32 ccid = keccak256("account1");
|
|
145
|
+
bytes memory credentialData = bytes("data");
|
|
146
|
+
|
|
147
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, 0, credentialData, "");
|
|
148
|
+
|
|
149
|
+
bytes32[] memory credentialTypeIds = new bytes32[](2);
|
|
150
|
+
credentialTypeIds[0] = CREDENTIAL_KYC;
|
|
151
|
+
credentialTypeIds[1] = CREDENTIAL_ACCREDITED;
|
|
152
|
+
|
|
153
|
+
vm.expectPartialRevert(ICredentialRegistry.CredentialNotFound.selector);
|
|
154
|
+
s_credentialRegistry.getCredentials(ccid, credentialTypeIds);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function test_renewCredential_success() public {
|
|
158
|
+
bytes32 ccid = keccak256("account1");
|
|
159
|
+
|
|
160
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, uint40(block.timestamp + 1), "", "");
|
|
161
|
+
vm.warp(block.timestamp + 10);
|
|
162
|
+
|
|
163
|
+
bool validateBeforeRenewal = s_credentialRegistry.validate(ccid, CREDENTIAL_KYC, "");
|
|
164
|
+
|
|
165
|
+
assert(validateBeforeRenewal == false);
|
|
166
|
+
|
|
167
|
+
s_credentialRegistry.renewCredential(ccid, CREDENTIAL_KYC, uint40(block.timestamp + 20), "");
|
|
168
|
+
|
|
169
|
+
bool validateAfterRenewal = s_credentialRegistry.validate(ccid, CREDENTIAL_KYC, "");
|
|
170
|
+
assert(validateAfterRenewal == true);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function test_renewCredential_emitsEventWithPreviousExpiry() public {
|
|
174
|
+
bytes32 ccid = keccak256("account1");
|
|
175
|
+
uint40 initialExpiry = uint40(block.timestamp + 100);
|
|
176
|
+
uint40 newExpiry = uint40(block.timestamp + 200);
|
|
177
|
+
|
|
178
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, initialExpiry, "", "");
|
|
179
|
+
|
|
180
|
+
vm.expectEmit();
|
|
181
|
+
emit ICredentialRegistry.CredentialRenewed(ccid, CREDENTIAL_KYC, initialExpiry, newExpiry);
|
|
182
|
+
|
|
183
|
+
s_credentialRegistry.renewCredential(ccid, CREDENTIAL_KYC, newExpiry, "");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function test_renewCredential_allowsShorteningCredential() public {
|
|
187
|
+
bytes32 ccid = keccak256("account1");
|
|
188
|
+
|
|
189
|
+
uint40 originalExpiry = uint40(block.timestamp + 100);
|
|
190
|
+
s_credentialRegistry.registerCredential(ccid, CREDENTIAL_KYC, originalExpiry, "", "");
|
|
191
|
+
|
|
192
|
+
uint40 shorterExpiry = uint40(block.timestamp + 50);
|
|
193
|
+
vm.expectEmit();
|
|
194
|
+
emit ICredentialRegistry.CredentialRenewed(ccid, CREDENTIAL_KYC, originalExpiry, shorterExpiry);
|
|
195
|
+
s_credentialRegistry.renewCredential(ccid, CREDENTIAL_KYC, shorterExpiry, "");
|
|
196
|
+
|
|
197
|
+
ICredentialRegistry.Credential memory credential = s_credentialRegistry.getCredential(ccid, CREDENTIAL_KYC);
|
|
198
|
+
assertEq(credential.expiresAt, shorterExpiry);
|
|
199
|
+
|
|
200
|
+
s_credentialRegistry.renewCredential(ccid, CREDENTIAL_KYC, shorterExpiry, "");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function test_validateAll_success() public {
|
|
204
|
+
bytes32 ccid = keccak256("account1");
|
|
205
|
+
|
|
206
|
+
bytes32[] memory credentialTypeIds = new bytes32[](2);
|
|
207
|
+
bytes[] memory credentialDatas = new bytes[](2);
|
|
208
|
+
|
|
209
|
+
credentialTypeIds[0] = CREDENTIAL_ACCREDITED;
|
|
210
|
+
credentialDatas[0] = "ACCREDITED";
|
|
211
|
+
|
|
212
|
+
credentialTypeIds[1] = CREDENTIAL_KYC;
|
|
213
|
+
credentialDatas[1] = "KYC";
|
|
214
|
+
|
|
215
|
+
s_credentialRegistry.registerCredentials(ccid, credentialTypeIds, 0, credentialDatas, "");
|
|
216
|
+
|
|
217
|
+
bool validateAllRes = s_credentialRegistry.validateAll(ccid, credentialTypeIds, "");
|
|
218
|
+
assert(validateAllRes == true);
|
|
219
|
+
}
|
|
220
|
+
}
|