-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed0bdc1
commit c456a30
Showing
10 changed files
with
8,319 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.6; | ||
|
||
contract EthereumDIDRegistry { | ||
|
||
mapping(address => address) public owners; | ||
mapping(address => mapping(bytes32 => mapping(address => uint))) public delegates; | ||
mapping(address => uint) public changed; | ||
mapping(address => uint) public nonce; | ||
|
||
modifier onlyOwner(address identity, address actor) { | ||
require (actor == identityOwner(identity), "bad_actor"); | ||
_; | ||
} | ||
|
||
event DIDOwnerChanged( | ||
address indexed identity, | ||
address owner, | ||
uint previousChange | ||
); | ||
|
||
event DIDDelegateChanged( | ||
address indexed identity, | ||
bytes32 delegateType, | ||
address delegate, | ||
uint validTo, | ||
uint previousChange | ||
); | ||
|
||
event DIDAttributeChanged( | ||
address indexed identity, | ||
bytes32 name, | ||
bytes value, | ||
uint validTo, | ||
uint previousChange | ||
); | ||
|
||
function identityOwner(address identity) public view returns(address) { | ||
address owner = owners[identity]; | ||
if (owner != address(0x00)) { | ||
return owner; | ||
} | ||
return identity; | ||
} | ||
|
||
function checkSignature(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 hash) internal returns(address) { | ||
address signer = ecrecover(hash, sigV, sigR, sigS); | ||
require(signer == identityOwner(identity), "bad_signature"); | ||
nonce[signer]++; | ||
return signer; | ||
} | ||
|
||
function validDelegate(address identity, bytes32 delegateType, address delegate) public view returns(bool) { | ||
uint validity = delegates[identity][keccak256(abi.encode(delegateType))][delegate]; | ||
return (validity > block.timestamp); | ||
} | ||
|
||
function changeOwner(address identity, address actor, address newOwner) internal onlyOwner(identity, actor) { | ||
owners[identity] = newOwner; | ||
emit DIDOwnerChanged(identity, newOwner, changed[identity]); | ||
changed[identity] = block.number; | ||
} | ||
|
||
function changeOwner(address identity, address newOwner) public { | ||
changeOwner(identity, msg.sender, newOwner); | ||
} | ||
|
||
function changeOwnerSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, address newOwner) public { | ||
bytes32 hash = keccak256(abi.encodePacked(bytes1(0x19), bytes1(0), this, nonce[identityOwner(identity)], identity, "changeOwner", newOwner)); | ||
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, hash), newOwner); | ||
} | ||
|
||
function addDelegate(address identity, address actor, bytes32 delegateType, address delegate, uint validity) internal onlyOwner(identity, actor) { | ||
delegates[identity][keccak256(abi.encode(delegateType))][delegate] = block.timestamp + validity; | ||
emit DIDDelegateChanged(identity, delegateType, delegate, block.timestamp + validity, changed[identity]); | ||
changed[identity] = block.number; | ||
} | ||
|
||
function addDelegate(address identity, bytes32 delegateType, address delegate, uint validity) public { | ||
addDelegate(identity, msg.sender, delegateType, delegate, validity); | ||
} | ||
|
||
function addDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 delegateType, address delegate, uint validity) public { | ||
bytes32 hash = keccak256(abi.encodePacked(bytes1(0x19), bytes1(0), this, nonce[identityOwner(identity)], identity, "addDelegate", delegateType, delegate, validity)); | ||
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate, validity); | ||
} | ||
|
||
function revokeDelegate(address identity, address actor, bytes32 delegateType, address delegate) internal onlyOwner(identity, actor) { | ||
delegates[identity][keccak256(abi.encode(delegateType))][delegate] = block.timestamp; | ||
emit DIDDelegateChanged(identity, delegateType, delegate, block.timestamp, changed[identity]); | ||
changed[identity] = block.number; | ||
} | ||
|
||
function revokeDelegate(address identity, bytes32 delegateType, address delegate) public { | ||
revokeDelegate(identity, msg.sender, delegateType, delegate); | ||
} | ||
|
||
function revokeDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 delegateType, address delegate) public { | ||
bytes32 hash = keccak256(abi.encodePacked(bytes1(0x19), bytes1(0), this, nonce[identityOwner(identity)], identity, "revokeDelegate", delegateType, delegate)); | ||
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate); | ||
} | ||
|
||
function setAttribute(address identity, address actor, bytes32 name, bytes memory value, uint validity ) internal onlyOwner(identity, actor) { | ||
emit DIDAttributeChanged(identity, name, value, block.timestamp + validity, changed[identity]); | ||
changed[identity] = block.number; | ||
} | ||
|
||
function setAttribute(address identity, bytes32 name, bytes memory value, uint validity) public { | ||
setAttribute(identity, msg.sender, name, value, validity); | ||
} | ||
|
||
function setAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 name, bytes memory value, uint validity) public { | ||
bytes32 hash = keccak256(abi.encodePacked(bytes1(0x19), bytes1(0), this, nonce[identityOwner(identity)], identity, "setAttribute", name, value, validity)); | ||
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value, validity); | ||
} | ||
|
||
function revokeAttribute(address identity, address actor, bytes32 name, bytes memory value ) internal onlyOwner(identity, actor) { | ||
emit DIDAttributeChanged(identity, name, value, 0, changed[identity]); | ||
changed[identity] = block.number; | ||
} | ||
|
||
function revokeAttribute(address identity, bytes32 name, bytes memory value) public { | ||
revokeAttribute(identity, msg.sender, name, value); | ||
} | ||
|
||
function revokeAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 name, bytes memory value) public { | ||
bytes32 hash = keccak256(abi.encodePacked(bytes1(0x19), bytes1(0), this, nonce[identityOwner(identity)], identity, "revokeAttribute", name, value)); | ||
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value); | ||
} | ||
|
||
} |
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,8 @@ | ||
import { HardhatUserConfig } from "hardhat/config"; | ||
import "@nomicfoundation/hardhat-toolbox"; | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: "0.8.27", | ||
}; | ||
|
||
export default config; |
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 @@ | ||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; | ||
//deploy DID registry contract to the hardhat network, | ||
const LockModule = buildModule("deployDIDreg", (m) => { | ||
|
||
const DIDr = m.contract("DIDRegistry"); | ||
|
||
return { DIDr }; | ||
}); | ||
|
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,7 @@ | ||
USECASES | ||
|
||
Content Management Systems -> need to check your age/property to see if you are an adult | ||
|
||
i need to | ||
|
||
generate atomic vc |
Oops, something went wrong.