Skip to content

Commit

Permalink
Resolver + PermissionManager v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cyri113 committed Jul 31, 2024
1 parent cdde5d3 commit 54e403a
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 12 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
16 changes: 16 additions & 0 deletions contracts/IOIDPermissionManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

interface IOIDPermissionManager {
event PermissionUpdated(string hash, address account, bool granted);
event PermissionDeleted(string hash, address account, bool granted);

function grantPermission(string memory hash, address account) external;

function revokePermission(string memory hash, address account) external;

function hasPermission(
string memory hash,
address account
) external view returns (bool);
}
1 change: 1 addition & 0 deletions contracts/Imports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pragma solidity ^0.8.26;

import "@ethereum-attestation-service/eas-contracts/contracts/SchemaRegistry.sol";
import "@ethereum-attestation-service/eas-contracts/contracts/EAS.sol";
import "@ethereum-attestation-service/eas-contracts/contracts/eip712/proxy/EIP712Proxy.sol";
28 changes: 28 additions & 0 deletions contracts/OIDPermissionManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IOIDPermissionManager} from "./IOIDPermissionManager.sol";

import "hardhat/console.sol";

contract OIDPermissionManager is IOIDPermissionManager {
mapping(string => mapping(address => bool)) private permissions;

function grantPermission(string memory hash, address account) external {
permissions[hash][account] = true;
}

function revokePermission(
string memory hash,
address account
) external override {
permissions[hash][account] = false;
}

function hasPermission(
string memory hash,
address account
) external view override returns (bool) {
return permissions[hash][account];
}
}
31 changes: 29 additions & 2 deletions contracts/OIDResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,52 @@ import {IEAS} from "@ethereum-attestation-service/eas-contracts/contracts/IEAS.s
import {Attestation} from "@ethereum-attestation-service/eas-contracts/contracts/Common.sol";
import {SchemaResolver} from "@ethereum-attestation-service/eas-contracts/contracts/resolver/SchemaResolver.sol";
import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";

import "hardhat/console.sol";

contract OIDResolver is SchemaResolver, AccessManagedUpgradeable {
error UnauthorizedAttester(address attester);

constructor(IEAS initialEAS) SchemaResolver(initialEAS) {}

modifier checkAttester(address attester) {
_checkAttester(attester);
_;
}

function initialize(address initialAuthority) public initializer {
__AccessManaged_init(initialAuthority);
}

function onAttest(
Attestation calldata attestation,
uint256 value
) internal virtual override returns (bool) {}
)
internal
virtual
override
checkAttester(attestation.attester)
returns (bool)
{
return true;
}

function onRevoke(
Attestation calldata attestation,
uint256 value
) internal virtual override returns (bool) {}
) internal virtual override returns (bool) {
return true;
}

function eas() public view returns (IEAS) {
return _eas;
}

function _checkAttester(address attester) internal virtual {
(bool isMember, ) = IAccessManager(authority()).hasRole(1, attester);
if (!isMember) {
revert UnauthorizedAttester(attester);
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/mocha": ">=9.1.0",
"@types/node": ">=18.0.0",
"chai": "^4.2.0",
"ethers": "^6.13.1",
"hardhat": "^2.14.0",
"hardhat-gas-reporter": "^1.0.8",
"solidity-coverage": "^0.8.0",
Expand Down
Loading

0 comments on commit 54e403a

Please sign in to comment.