Skip to content

Commit

Permalink
Merge branch 'release/v0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
pelle committed Jun 15, 2018
2 parents 829b0e4 + fb53b4e commit 4278342
Show file tree
Hide file tree
Showing 7 changed files with 20,538 additions and 11,219 deletions.
17 changes: 4 additions & 13 deletions README.md
Expand Up @@ -40,10 +40,10 @@ let didReg = DidReg.at(DidRegistryContract.networks[networkId].address)
## Contract Deployments
|Network|Address|
| --|--|
|Mainnet (id: 1)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
|Ropsten (id: 3)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://ropsten.etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
|Rinkeby (id: 4)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://rinkeby.etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
|Kovan (id: 42)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://kovan.etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
|Mainnet (id: 1)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|
|Ropsten (id: 3)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://ropsten.etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|
|Rinkeby (id: 4)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://rinkeby.etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|
|Kovan (id: 42)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://kovan.etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|

## On-chain vs Off-chain
For on-chain interactions Ethereum has a built in account abstraction that can be used regardless of whether the account is a smart contract or a key pair. Any transaction has a `msg.sender` as the verified send of the transaction.
Expand Down Expand Up @@ -98,15 +98,6 @@ Validity is set using amount of seconds from the time that adding the delegate i
### Looking up a delegate
You can check if an address is a delegate for an identity using the`validDelegate(address identity, string delegateType, address delegate) returns(bool)` function. This returns true if the address is a valid delegate of the given delegateType.

### Checking a delegate signature
The registry provides a handy function for checking an externally signed signature in your own contracts and validating it is a particular kind of delegate.

This frees you from adding nonce and signature management code in your own contracts.

`validDelegateSignature(address identity, string delegateType, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 hash) public returns(address)`

In your own code you will need to calculate the hash yourself.

### Adding a delegate

An identity can assign multiple delegates to manage signing on their behalf for specific purposes.
Expand Down
28,818 changes: 18,581 additions & 10,237 deletions build/contracts/EthereumDIDRegistry.json

Large diffs are not rendered by default.

64 changes: 27 additions & 37 deletions contracts/EthereumDIDRegistry.sol
Expand Up @@ -20,23 +20,20 @@ contract EthereumDIDRegistry {

event DIDDelegateChanged(
address indexed identity,
string delegateType,
bytes32 delegateType,
address delegate,
uint validTo,
uint previousChange
);

event DIDAttributeChanged(
address indexed identity,
string name,
bytes32 name,
bytes value,
uint validTo,
uint previousChange
);

function EthereumDIDRegistry() public {
}

function identityOwner(address identity) public view returns(address) {
address owner = owners[identity];
if (owner != 0x0) {
Expand All @@ -52,21 +49,14 @@ contract EthereumDIDRegistry {
return signer;
}

function validDelegate(address identity, string delegateType, address delegate) public view returns(bool) {
function validDelegate(address identity, bytes32 delegateType, address delegate) public view returns(bool) {
uint validity = delegates[identity][keccak256(delegateType)][delegate];
return (validity >= block.timestamp);
}

function validDelegateSignature(address identity, string delegateType, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 hash) public returns(address) {
address signer = ecrecover(hash, sigV, sigR, sigS);
require(validDelegate(identity, delegateType, signer));
nonce[signer]++;
return signer;
return (validity > now);
}

function changeOwner(address identity, address actor, address newOwner) internal onlyOwner(identity, actor) {
owners[identity] = newOwner;
DIDOwnerChanged(identity, newOwner, changed[identity]);
emit DIDOwnerChanged(identity, newOwner, changed[identity]);
changed[identity] = block.number;
}

Expand All @@ -75,64 +65,64 @@ contract EthereumDIDRegistry {
}

function changeOwnerSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, address newOwner) public {
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "changeOwner", newOwner);
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "changeOwner", newOwner);
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, hash), newOwner);
}

function addDelegate(address identity, address actor, string delegateType, address delegate, uint validity ) internal onlyOwner(identity, actor) {
delegates[identity][keccak256(delegateType)][delegate] = block.timestamp + validity;
DIDDelegateChanged(identity, delegateType, delegate, block.timestamp + validity, changed[identity]);
function addDelegate(address identity, address actor, bytes32 delegateType, address delegate, uint validity) internal onlyOwner(identity, actor) {
delegates[identity][keccak256(delegateType)][delegate] = now + validity;
emit DIDDelegateChanged(identity, delegateType, delegate, now + validity, changed[identity]);
changed[identity] = block.number;
}

function addDelegate(address identity, string delegateType, address delegate, uint validity) public {
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, string delegateType, address delegate, uint validity) public {
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "addDelegate", delegateType, delegate, validity);
function addDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 delegateType, address delegate, uint validity) public {
bytes32 hash = keccak256(byte(0x19), byte(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, string delegateType, address delegate) internal onlyOwner(identity, actor) {
delegates[identity][keccak256(delegateType)][delegate] = 0;
DIDDelegateChanged(identity, delegateType, delegate, 0, changed[identity]);
function revokeDelegate(address identity, address actor, bytes32 delegateType, address delegate) internal onlyOwner(identity, actor) {
delegates[identity][keccak256(delegateType)][delegate] = now;
emit DIDDelegateChanged(identity, delegateType, delegate, now, changed[identity]);
changed[identity] = block.number;
}

function revokeDelegate(address identity, string delegateType, address delegate) public {
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, string delegateType, address delegate) public {
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "revokeDelegate", delegateType, delegate);
function revokeDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 delegateType, address delegate) public {
bytes32 hash = keccak256(byte(0x19), byte(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, string name, bytes value, uint validity ) internal onlyOwner(identity, actor) {
DIDAttributeChanged(identity, name, value, block.timestamp + validity, changed[identity]);
function setAttribute(address identity, address actor, bytes32 name, bytes value, uint validity ) internal onlyOwner(identity, actor) {
emit DIDAttributeChanged(identity, name, value, now + validity, changed[identity]);
changed[identity] = block.number;
}

function setAttribute(address identity, string name, bytes value, uint validity) public {
function setAttribute(address identity, bytes32 name, bytes value, uint validity) public {
setAttribute(identity, msg.sender, name, value, validity);
}

function setAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, string name, bytes value, uint validity) public {
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identity], identity, "setAttribute", name, value, validity);
function setAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 name, bytes value, uint validity) public {
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identity], identity, "setAttribute", name, value, validity);
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value, validity);
}

function revokeAttribute(address identity, address actor, string name, bytes value ) internal onlyOwner(identity, actor) {
DIDAttributeChanged(identity, name, value, 0, changed[identity]);
function revokeAttribute(address identity, address actor, bytes32 name, bytes value ) internal onlyOwner(identity, actor) {
emit DIDAttributeChanged(identity, name, value, 0, changed[identity]);
changed[identity] = block.number;
}

function revokeAttribute(address identity, string name, bytes value) public {
function revokeAttribute(address identity, bytes32 name, bytes value) public {
revokeAttribute(identity, msg.sender, name, value);
}

function revokeAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, string name, bytes value) public {
function revokeAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 name, bytes value) public {
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identity], identity, "revokeAttribute", name, value);
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "ethr-did-registry",
"version": "0.0.2",
"version": "0.0.3",
"description": "A repository storing keys and other data about Decentralized Identifiers (DIDs)",
"main": "build/contracts/EthereumDIDRegistry.json",
"directories": {
Expand All @@ -14,7 +14,7 @@
"js-sha3": "^0.7.0",
"ls": "^0.2.1",
"solhint": "^1.1.10",
"truffle": "^4.0.6",
"truffle": "^4.1.6",
"truffle-hdwallet-provider": "^0.0.3"
},
"scripts": {
Expand Down

0 comments on commit 4278342

Please sign in to comment.