Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions contracts/interfaces/IHasher.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

/**
* @dev IHasher. Interface for generating hashes. Specifically used for Merkle Tree hashing.
*/
interface IHasher {
/**
* @dev hash2. hashes two uint256 parameters and returns the resulting hash as uint256.
* @param params The parameters array of size 2 to be hashed.
* @return The resulting hash as uint256.
*/
function hash2(uint256[2] memory params) external pure returns (uint256);

/**
* @dev hash3. hashes three uint256 parameters and returns the resulting hash as uint256.
* @param params The parameters array of size 3 to be hashed.
* @return The resulting hash as uint256.
*/
function hash3(uint256[3] memory params) external pure returns (uint256);
}
6 changes: 4 additions & 2 deletions contracts/lib/IdentityBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {IOnchainCredentialStatusResolver} from "../interfaces/IOnchainCredential
import {IdentityLib} from "../lib/IdentityLib.sol";
import {SmtLib} from "../lib/SmtLib.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IHasher} from "../interfaces/IHasher.sol";

error IdentityIdMismatch();

Expand Down Expand Up @@ -46,12 +47,13 @@ abstract contract IdentityBase is IIdentifiable, IOnchainCredentialStatusResolve
* @dev Initialization of IdentityLib library
* @param _stateContractAddr - address of the State contract
*/
function initialize(address _stateContractAddr, bytes2 idType) public virtual {
function initialize(address _stateContractAddr, bytes2 idType, IHasher hasher) public virtual {
_getIdentityBaseStorage().identity.initialize(
_stateContractAddr,
address(this),
getSmtDepth(),
idType
idType,
hasher
);
}

Expand Down
10 changes: 6 additions & 4 deletions contracts/lib/IdentityLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {IState} from "../interfaces/IState.sol";
import {SmtLib} from "../lib/SmtLib.sol";
import {PoseidonUnit3L, PoseidonUnit4L} from "../lib/Poseidon.sol";
import {GenesisUtils} from "../lib/GenesisUtils.sol";
import {IHasher} from "../interfaces/IHasher.sol";

error SMTDepthIsGreaterThanMaxAllowed();
error IdTypeNotSupported();
Expand Down Expand Up @@ -86,7 +87,8 @@ library IdentityLib {
address _stateContractAddr,
address _identityAddr,
uint256 depth,
bytes2 idType
bytes2 idType,
IHasher hasher
) external {
if (depth > IDENTITY_MAX_SMT_DEPTH) {
revert SMTDepthIsGreaterThanMaxAllowed();
Expand All @@ -96,9 +98,9 @@ library IdentityLib {
revert IdTypeNotSupported();
}
self.isOldStateGenesis = true;
self.trees.claimsTree.initialize(depth);
self.trees.revocationsTree.initialize(depth);
self.trees.rootsTree.initialize(depth);
self.trees.claimsTree.initialize(depth, hasher);
self.trees.revocationsTree.initialize(depth, hasher);
self.trees.rootsTree.initialize(depth, hasher);
self.id = GenesisUtils.calcIdFromEthAddress(idType, _identityAddr);
}

Expand Down
Loading
Loading