-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from KPrasch/auth
TACo Encryption Allow Logic Interfaces
- Loading branch information
Showing
5 changed files
with
276 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
pragma solidity ^0.8.0; | ||
import "@openzeppelin/contracts/access/AccessControlDefaultAdminRules.sol"; | ||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
import "./IEncryptionAuthorizer.sol"; | ||
import "./Coordinator.sol"; | ||
|
||
|
||
contract GlobalAllowList is AccessControlDefaultAdminRules, IEncryptionAuthorizer { | ||
using ECDSA for bytes32; | ||
|
||
Coordinator public coordinator; | ||
mapping(uint256 => mapping(address => bool)) public authorizations; | ||
|
||
constructor( | ||
Coordinator _coordinator, | ||
address _admin | ||
) AccessControlDefaultAdminRules(0, _admin) { | ||
require(address(_coordinator) != address(0), "Coordinator cannot be zero address"); | ||
require(_coordinator.numberOfRituals() >= 0, "Invalid coordinator"); | ||
coordinator = _coordinator; | ||
} | ||
|
||
modifier onlyAuthority(uint32 ritualId) { | ||
require(coordinator.getAuthority(ritualId) == msg.sender, | ||
"Only ritual authority is permitted"); | ||
_; | ||
} | ||
|
||
function setCoordinator(Coordinator _coordinator) public { | ||
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Only admin can set coordinator"); | ||
coordinator = _coordinator; | ||
} | ||
|
||
function isAuthorized( | ||
uint32 ritualId, | ||
bytes memory evidence, | ||
bytes32 digest | ||
) public view override returns(bool) { | ||
address recovered_address = digest.toEthSignedMessageHash().recover(evidence); | ||
return authorizations[ritualId][recovered_address]; | ||
} | ||
|
||
function authorize(uint32 ritualId, address[] calldata addresses) public onlyAuthority(ritualId) { | ||
require(coordinator.isRitualFinalized(ritualId), | ||
"Only active rituals can add authorizations"); | ||
for (uint256 i=0; i < addresses.length; i++) { | ||
authorizations[ritualId][addresses[i]] = true; | ||
} | ||
} | ||
|
||
function deauthorize(uint32 ritualId, address[] calldata addresses) public onlyAuthority(ritualId) { | ||
require(coordinator.isRitualFinalized(ritualId), | ||
"Only active rituals can add authorizations"); | ||
for (uint256 i=0; i < addresses.length; i++) { | ||
authorizations[ritualId][addresses[i]] = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
interface IEncryptionAuthorizer { | ||
function isAuthorized( | ||
uint32 ritualID, | ||
bytes memory evidence, // signature | ||
bytes32 digest // signed message hash | ||
) external view returns(bool); | ||
} |
Oops, something went wrong.