Skip to content

Commit

Permalink
separation of delegates and challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
axelpoise committed May 17, 2016
1 parent 1a67bda commit 0697f81
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/contracts/WalletTrust.sol

This file was deleted.

8 changes: 8 additions & 0 deletions src/contracts/alternative setup/Challenge.sol
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){}

}
28 changes: 28 additions & 0 deletions src/contracts/alternative setup/Grant.sol
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);
}

}
67 changes: 67 additions & 0 deletions src/contracts/alternative setup/Party.sol
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];
}

}
36 changes: 36 additions & 0 deletions src/contracts/alternative setup/PasswordChallenge.sol
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;
}
}

0 comments on commit 0697f81

Please sign in to comment.