-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separation of delegates and challenges
- Loading branch information
Showing
5 changed files
with
139 additions
and
38 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
contract Challenge{ | ||
|
||
event error(); | ||
event success(); | ||
|
||
function authorize(uint8 v, bytes32 r, bytes32 s, address party, address grant){} | ||
|
||
} |
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,28 @@ | ||
contract Grant { | ||
|
||
address client; | ||
address owner; | ||
|
||
function Grant(address _client) { | ||
client = _client; | ||
} | ||
|
||
/* | ||
* authorize the grant contract | ||
* this can only be done once | ||
*/ | ||
function authorize() { | ||
if(msg.sender != owner) throw; | ||
owner = msg.sender; | ||
} | ||
|
||
/* | ||
* revoke the grant contract | ||
* this can be done by the client or owner | ||
*/ | ||
function revoke() { | ||
if(msg.sender != client && msg.sender != owner) throw; | ||
suicide(msg.sender); | ||
} | ||
|
||
} |
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,67 @@ | ||
contract Party { | ||
|
||
mapping (address => uint) delegates; | ||
|
||
mapping(address=>bool) challenges; | ||
mapping(address=>bool) usedChallenges; | ||
|
||
modifier isTrusted(uint a){ | ||
if(delegates[msg.sender] < a){ | ||
return; | ||
} | ||
} | ||
|
||
modifier isNewChallenge(){ | ||
if(!challenges[msg.sender]){throw;} | ||
if(usedChallenges[msg.sender]){throw;} | ||
} | ||
/* | ||
* constructor set sender as first delegate | ||
*/ | ||
function Party () { | ||
delegates[msg.sender] = 2; | ||
//TODO add challenges | ||
} | ||
|
||
/* | ||
* authorize contract of type grant | ||
*/ | ||
function authorize (address grant) isTrusted(2) { | ||
|
||
Grant(grant).authorize(); | ||
} | ||
|
||
/* | ||
* enroll new address as delegate to the contract | ||
*/ | ||
function enroll (address delegate) isTrusted(2){ | ||
|
||
delegates[delegate] = 1; | ||
} | ||
|
||
/* | ||
* increase trustlevel | ||
*/ | ||
function increaseTrust(address delegate) isNewChallenge{ | ||
delegates[delegate] += 1; | ||
usedChallenges[msg.sender] = true; | ||
} | ||
|
||
/* | ||
* add challenge | ||
*/ | ||
function addChallenge(address challenge) isTrusted(4){ | ||
challenges[challenge]= true; | ||
//TODO challenges must be invoked from here. | ||
} | ||
|
||
/* | ||
* abandon a delegate from the contract | ||
*/ | ||
function abandon (address delegate) isTrusted(2) { | ||
|
||
if(delegates[delegate] == 0) throw; | ||
delete delegates[delegate]; | ||
} | ||
|
||
} |
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,36 @@ | ||
contract PasswordChallenge is Challenge{ | ||
|
||
bytes32 private salt; | ||
bytes32 private challenge; | ||
bytes20 private response; | ||
|
||
function PasswordChallenge(bytes20 _response, bytes32 _salt){ | ||
response = _response; | ||
salt = _salt; | ||
challenge = sha3(_salt); | ||
} | ||
|
||
function getSalt() constant returns(bytes32){ | ||
return salt; | ||
} | ||
|
||
function getChallenge() constant returns(bytes32){ | ||
return challenge; | ||
} | ||
|
||
function getResponse() constant returns(bytes20){ | ||
return response; | ||
} | ||
|
||
function increaseTrust(uint8 v, bytes32 r, bytes32 s, address party, address grant) { | ||
if(!verify(v, r, s)) return error(); | ||
Party(party).increaseTrust(msg.sender); | ||
return success(); | ||
} | ||
|
||
function verify(uint8 v, bytes32 r, bytes32 s) returns (bool) { | ||
var result = (bytes20(ecrecover(challenge, v, r, s)) == response); | ||
challenge = sha3(challenge); | ||
return result; | ||
} | ||
} |