Skip to content

Commit 4278342

Browse files
committed
Merge branch 'release/v0.0.3'
2 parents 829b0e4 + fb53b4e commit 4278342

File tree

7 files changed

+20538
-11219
lines changed

7 files changed

+20538
-11219
lines changed

README.md

+4-13
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ let didReg = DidReg.at(DidRegistryContract.networks[networkId].address)
4040
## Contract Deployments
4141
|Network|Address|
4242
| --|--|
43-
|Mainnet (id: 1)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
44-
|Ropsten (id: 3)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://ropsten.etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
45-
|Rinkeby (id: 4)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://rinkeby.etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
46-
|Kovan (id: 42)|[0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275](https://kovan.etherscan.io/address/0x160c5ce58e2cc4fe7cc45a9dd569a10083b2a275)|
43+
|Mainnet (id: 1)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|
44+
|Ropsten (id: 3)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://ropsten.etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|
45+
|Rinkeby (id: 4)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://rinkeby.etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|
46+
|Kovan (id: 42)|[0xdca7ef03e98e0dc2b855be647c39abe984fcf21b](https://kovan.etherscan.io/address/0xdca7ef03e98e0dc2b855be647c39abe984fcf21b)|
4747

4848
## On-chain vs Off-chain
4949
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.
@@ -98,15 +98,6 @@ Validity is set using amount of seconds from the time that adding the delegate i
9898
### Looking up a delegate
9999
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.
100100

101-
### Checking a delegate signature
102-
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.
103-
104-
This frees you from adding nonce and signature management code in your own contracts.
105-
106-
`validDelegateSignature(address identity, string delegateType, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 hash) public returns(address)`
107-
108-
In your own code you will need to calculate the hash yourself.
109-
110101
### Adding a delegate
111102

112103
An identity can assign multiple delegates to manage signing on their behalf for specific purposes.

build/contracts/EthereumDIDRegistry.json

+18,581-10,237
Large diffs are not rendered by default.

contracts/EthereumDIDRegistry.sol

+27-37
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,20 @@ contract EthereumDIDRegistry {
2020

2121
event DIDDelegateChanged(
2222
address indexed identity,
23-
string delegateType,
23+
bytes32 delegateType,
2424
address delegate,
2525
uint validTo,
2626
uint previousChange
2727
);
2828

2929
event DIDAttributeChanged(
3030
address indexed identity,
31-
string name,
31+
bytes32 name,
3232
bytes value,
3333
uint validTo,
3434
uint previousChange
3535
);
3636

37-
function EthereumDIDRegistry() public {
38-
}
39-
4037
function identityOwner(address identity) public view returns(address) {
4138
address owner = owners[identity];
4239
if (owner != 0x0) {
@@ -52,21 +49,14 @@ contract EthereumDIDRegistry {
5249
return signer;
5350
}
5451

55-
function validDelegate(address identity, string delegateType, address delegate) public view returns(bool) {
52+
function validDelegate(address identity, bytes32 delegateType, address delegate) public view returns(bool) {
5653
uint validity = delegates[identity][keccak256(delegateType)][delegate];
57-
return (validity >= block.timestamp);
58-
}
59-
60-
function validDelegateSignature(address identity, string delegateType, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 hash) public returns(address) {
61-
address signer = ecrecover(hash, sigV, sigR, sigS);
62-
require(validDelegate(identity, delegateType, signer));
63-
nonce[signer]++;
64-
return signer;
54+
return (validity > now);
6555
}
6656

6757
function changeOwner(address identity, address actor, address newOwner) internal onlyOwner(identity, actor) {
6858
owners[identity] = newOwner;
69-
DIDOwnerChanged(identity, newOwner, changed[identity]);
59+
emit DIDOwnerChanged(identity, newOwner, changed[identity]);
7060
changed[identity] = block.number;
7161
}
7262

@@ -75,64 +65,64 @@ contract EthereumDIDRegistry {
7565
}
7666

7767
function changeOwnerSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, address newOwner) public {
78-
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "changeOwner", newOwner);
68+
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "changeOwner", newOwner);
7969
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, hash), newOwner);
8070
}
8171

82-
function addDelegate(address identity, address actor, string delegateType, address delegate, uint validity ) internal onlyOwner(identity, actor) {
83-
delegates[identity][keccak256(delegateType)][delegate] = block.timestamp + validity;
84-
DIDDelegateChanged(identity, delegateType, delegate, block.timestamp + validity, changed[identity]);
72+
function addDelegate(address identity, address actor, bytes32 delegateType, address delegate, uint validity) internal onlyOwner(identity, actor) {
73+
delegates[identity][keccak256(delegateType)][delegate] = now + validity;
74+
emit DIDDelegateChanged(identity, delegateType, delegate, now + validity, changed[identity]);
8575
changed[identity] = block.number;
8676
}
8777

88-
function addDelegate(address identity, string delegateType, address delegate, uint validity) public {
78+
function addDelegate(address identity, bytes32 delegateType, address delegate, uint validity) public {
8979
addDelegate(identity, msg.sender, delegateType, delegate, validity);
9080
}
9181

92-
function addDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, string delegateType, address delegate, uint validity) public {
93-
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "addDelegate", delegateType, delegate, validity);
82+
function addDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 delegateType, address delegate, uint validity) public {
83+
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "addDelegate", delegateType, delegate, validity);
9484
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate, validity);
9585
}
9686

97-
function revokeDelegate(address identity, address actor, string delegateType, address delegate) internal onlyOwner(identity, actor) {
98-
delegates[identity][keccak256(delegateType)][delegate] = 0;
99-
DIDDelegateChanged(identity, delegateType, delegate, 0, changed[identity]);
87+
function revokeDelegate(address identity, address actor, bytes32 delegateType, address delegate) internal onlyOwner(identity, actor) {
88+
delegates[identity][keccak256(delegateType)][delegate] = now;
89+
emit DIDDelegateChanged(identity, delegateType, delegate, now, changed[identity]);
10090
changed[identity] = block.number;
10191
}
10292

103-
function revokeDelegate(address identity, string delegateType, address delegate) public {
93+
function revokeDelegate(address identity, bytes32 delegateType, address delegate) public {
10494
revokeDelegate(identity, msg.sender, delegateType, delegate);
10595
}
10696

107-
function revokeDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, string delegateType, address delegate) public {
108-
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "revokeDelegate", delegateType, delegate);
97+
function revokeDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 delegateType, address delegate) public {
98+
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identityOwner(identity)], identity, "revokeDelegate", delegateType, delegate);
10999
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate);
110100
}
111101

112-
function setAttribute(address identity, address actor, string name, bytes value, uint validity ) internal onlyOwner(identity, actor) {
113-
DIDAttributeChanged(identity, name, value, block.timestamp + validity, changed[identity]);
102+
function setAttribute(address identity, address actor, bytes32 name, bytes value, uint validity ) internal onlyOwner(identity, actor) {
103+
emit DIDAttributeChanged(identity, name, value, now + validity, changed[identity]);
114104
changed[identity] = block.number;
115105
}
116106

117-
function setAttribute(address identity, string name, bytes value, uint validity) public {
107+
function setAttribute(address identity, bytes32 name, bytes value, uint validity) public {
118108
setAttribute(identity, msg.sender, name, value, validity);
119109
}
120110

121-
function setAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, string name, bytes value, uint validity) public {
122-
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identity], identity, "setAttribute", name, value, validity);
111+
function setAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 name, bytes value, uint validity) public {
112+
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identity], identity, "setAttribute", name, value, validity);
123113
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value, validity);
124114
}
125115

126-
function revokeAttribute(address identity, address actor, string name, bytes value ) internal onlyOwner(identity, actor) {
127-
DIDAttributeChanged(identity, name, value, 0, changed[identity]);
116+
function revokeAttribute(address identity, address actor, bytes32 name, bytes value ) internal onlyOwner(identity, actor) {
117+
emit DIDAttributeChanged(identity, name, value, 0, changed[identity]);
128118
changed[identity] = block.number;
129119
}
130120

131-
function revokeAttribute(address identity, string name, bytes value) public {
121+
function revokeAttribute(address identity, bytes32 name, bytes value) public {
132122
revokeAttribute(identity, msg.sender, name, value);
133123
}
134124

135-
function revokeAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, string name, bytes value) public {
125+
function revokeAttributeSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 name, bytes value) public {
136126
bytes32 hash = keccak256(byte(0x19), byte(0), this, nonce[identity], identity, "revokeAttribute", name, value);
137127
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value);
138128
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethr-did-registry",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A repository storing keys and other data about Decentralized Identifiers (DIDs)",
55
"main": "build/contracts/EthereumDIDRegistry.json",
66
"directories": {
@@ -14,7 +14,7 @@
1414
"js-sha3": "^0.7.0",
1515
"ls": "^0.2.1",
1616
"solhint": "^1.1.10",
17-
"truffle": "^4.0.6",
17+
"truffle": "^4.1.6",
1818
"truffle-hdwallet-provider": "^0.0.3"
1919
},
2020
"scripts": {

0 commit comments

Comments
 (0)