Skip to content

Instantly share code, notes, and snippets.

@sumitpatel93
Last active April 16, 2020 18:40
Show Gist options
  • Save sumitpatel93/70cf5cd0e0ad55fcff06d4e718bd19b4 to your computer and use it in GitHub Desktop.
Save sumitpatel93/70cf5cd0e0ad55fcff06d4e718bd19b4 to your computer and use it in GitHub Desktop.
pragma solidity = 0.4.25;
contract IdentityRegistration {
struct UserDetails
{
uint256 userId;
bytes32 Name;
bytes32 city;
bytes32 college;
bytes32 university;
bytes32 UserAddress;
}
mapping ( uint256 => UserDetails ) userdetail;
address owner ;
address AccountManager;
address AttributeManager;
address User;
mapping (bytes32 => address ) RelyingParties;
//sets contract owner
constructor(string memory _certificateAuthorityName ) public {
owner = msg.sender;
certificateAuthority = msg.sender;
certificateAuthorityName = _certificateAuthorityName;
}
//onlyOwner modifier
modifier onlyOwner {
require( msg.sender == owner );
_;
}
//AccountManager modifier
modifier onlyAccountManager {
require (msg.sender == AccountManager );
_;
}
modifier onlyAttributeManager {
require (msg.sender == AttributeManager );
_;
}
function addAccountManagers(address _AccountManager ) onlyOwner public {
AccountManager = _AccountManager;
"Only owner";
}
function deleteAccountManager(address _newAccountManager ) onlyOwner public {
AccountManager = _newAccountManager;
delete AccountManager;
}
function addAttributeManager(address _AttributeManager ) onlyOwner public {
AttributeManager = _AttributeManager;
"Only owner";
}
function addUsers(address _Users ) onlyAccountManager public {
User = _Users;
}
function deleteUser(address _newUser ) onlyAccountManager public {
User = _newUser;
delete User;
}
function getUser() public view returns(address) {
return User;
}
function getAccoutManager() public view returns(address){
return AccountManager;
}
function getAttributeManager() public view returns(address){
return AttributeManager;
}
address public certificateAuthority;
string public certificateAuthorityName;
event Issued(bytes32 key);
mapping(bytes32 => bytes32) certificate;
function issue(bytes32 _regNo, bytes32 _name, uint _percentile ,bytes32 _univName) external {
require(msg.sender == certificateAuthority);
require(certificate[keccak256(abi.encodePacked(_regNo))] == 0);
bytes32 key = keccak256(abi.encodePacked(_regNo));
certificate[key] = keccak256(abi.encodePacked(_regNo, _name, _percentile, _univName ));
emit Issued(key); //fire issued event
}
function verify(bytes32 _regNo, bytes32 _name, uint _percentile , bytes32 _univName) public view returns(bool) {
if (certificate[keccak256(abi.encodePacked(_regNo))] == keccak256(abi.encodePacked(_regNo, _name, _percentile, _univName))) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment