Skip to content

Commit

Permalink
feat: remove eas and add key to Permisson contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Nov 20, 2024
1 parent 1a97a87 commit 15f6707
Show file tree
Hide file tree
Showing 5 changed files with 12,891 additions and 6,652 deletions.
13 changes: 5 additions & 8 deletions contracts/IOIDPermissionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
pragma solidity 0.8.26;

interface IOIDPermissionManager {
event PermissionUpdated(bytes32 uid, address account, bool granted);

function grantPermission(bytes32 uid, address account) external;

function revokePermission(bytes32 uid, address account) external;

event PermissionUpdated(bytes32 key, address account, bool granted);
function grantPermission(bytes32 key, address account) external;
function revokePermission(bytes32 key, address account) external;
function hasPermission(
bytes32 uid,
bytes32 key,
address account
) external view returns (bool);
}
}
51 changes: 13 additions & 38 deletions contracts/OIDPermissionManager.sol
Original file line number Diff line number Diff line change
@@ -1,68 +1,46 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IOIDPermissionManager} from "./IOIDPermissionManager.sol";
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";
import {IEAS} from "@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol";
import {Attestation} from "@ethereum-attestation-service/eas-contracts/contracts/Common.sol";
import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
import {OIDAccessManager} from "./OIDAccessManager.sol";

contract OIDPermissionManager is IOIDPermissionManager, AccessManaged {
error UnauthorizedAccess(address caller);

IEAS internal immutable _eas;

mapping(bytes32 => mapping(address => bool)) private permissions;

constructor(
address initialAuthority,
IEAS initialEAS
address initialAuthority
) AccessManaged(initialAuthority) {
_eas = initialEAS;
}

function grantPermission(bytes32 uid, address account) external {
_checkValid(uid);
permissions[uid][account] = true;
emit PermissionUpdated(uid, account, true);
}

function revokePermission(bytes32 uid, address account) external override {
_checkValid(uid);
permissions[uid][account] = false;
emit PermissionUpdated(uid, account, false);
function grantPermission(bytes32 key, address account) external {
_checkValid();
permissions[key][account] = true;
emit PermissionUpdated(key, account, true);
}

function hasPermission(
bytes32 uid,
address account
) external view override returns (bool) {
Attestation memory attestation = _eas.getAttestation(uid);

if (attestation.revocationTime == 0) {
return permissions[uid][account];
} else {
return false;
}
function revokePermission(bytes32 key, address account) external override {
_checkValid();
permissions[key][account] = false;
emit PermissionUpdated(key, account, false);
}

function eas() external view returns (IEAS) {
return _eas;
function hasPermission(bytes32 key,address account) external view override returns (bool) {
return permissions[key][account];
}

function _checkValid(bytes32 uid) internal view {
bool valid = _isAttestationRecipient(uid) || _isPermissionManager();

function _checkValid() internal view {
bool valid = _isPermissionManager();
if (!valid) {
revert UnauthorizedAccess(msg.sender);
}
}

function _isAttestationRecipient(bytes32 uid) internal view returns (bool) {
Attestation memory attestation = _eas.getAttestation(uid);
return attestation.recipient == msg.sender;
}

function _isPermissionManager() internal view returns (bool) {
OIDAccessManager access = OIDAccessManager(authority());
Expand All @@ -73,7 +51,4 @@ contract OIDPermissionManager is IOIDPermissionManager, AccessManaged {
return isMember;
}

Check warning

Code scanning / Slither

Unused return Medium


// function _isApplication(address account) internal view returns (bool) {
// return msg.sender == account;
// }
}
Loading

0 comments on commit 15f6707

Please sign in to comment.