2018-02-21 21:17:38 +00:00
|
|
|
pragma solidity ^0.4.17;
|
|
|
|
|
|
|
|
import "./ERC725.sol";
|
|
|
|
import "./ERC735.sol";
|
|
|
|
|
2018-02-28 18:52:32 +00:00
|
|
|
|
2018-02-21 21:17:38 +00:00
|
|
|
contract Identity is ERC725, ERC735 {
|
|
|
|
|
|
|
|
mapping (bytes32 => Key) keys;
|
|
|
|
mapping (bytes32 => Claim) claims;
|
|
|
|
mapping (uint256 => bytes32[]) keysByPurpose;
|
|
|
|
mapping (uint256 => bytes32[]) claimsByType;
|
|
|
|
mapping (bytes32 => uint256) indexes;
|
|
|
|
mapping (uint => Transaction) txx;
|
2018-03-02 19:00:46 +00:00
|
|
|
mapping (uint256 => uint256) minimumApprovalsByKeyPurpose;
|
2018-02-21 21:17:38 +00:00
|
|
|
bytes32[] pendingTransactions;
|
|
|
|
uint nonce = 0;
|
2018-02-27 17:23:00 +00:00
|
|
|
address recoveryContract;
|
2018-03-02 19:00:46 +00:00
|
|
|
address recoveryManager;
|
2018-02-21 21:17:38 +00:00
|
|
|
|
|
|
|
struct Transaction {
|
|
|
|
address to;
|
|
|
|
uint value;
|
|
|
|
bytes data;
|
|
|
|
uint nonce;
|
|
|
|
uint approverCount;
|
|
|
|
mapping(bytes32 => bool) approvals;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-02-21 21:17:38 +00:00
|
|
|
modifier managerOnly {
|
2018-02-27 17:23:00 +00:00
|
|
|
require(
|
2018-03-02 14:32:00 +00:00
|
|
|
isKeyType(bytes32(msg.sender), MANAGEMENT_KEY)
|
2018-02-27 17:23:00 +00:00
|
|
|
);
|
2018-02-21 21:17:38 +00:00
|
|
|
_;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-02-22 08:16:06 +00:00
|
|
|
modifier selfOnly {
|
2018-02-27 17:23:00 +00:00
|
|
|
require(
|
2018-03-02 14:32:00 +00:00
|
|
|
msg.sender == address(this)
|
|
|
|
);
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
modifier recoveryOnly {
|
|
|
|
require(
|
|
|
|
(recoveryContract != address(0) && msg.sender == address(recoveryContract))
|
2018-02-27 17:23:00 +00:00
|
|
|
);
|
2018-02-21 21:17:38 +00:00
|
|
|
_;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-02-26 22:22:04 +00:00
|
|
|
modifier actorOnly(bytes32 _key) {
|
|
|
|
require(isKeyType(_key, ACTION_KEY));
|
2018-02-21 21:17:38 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2018-02-26 22:22:04 +00:00
|
|
|
modifier managerOrActor(bytes32 _key) {
|
2018-03-02 19:00:46 +00:00
|
|
|
|
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
require(
|
|
|
|
isKeyType(bytes32(msg.sender), MANAGEMENT_KEY) ||
|
2018-03-02 19:00:46 +00:00
|
|
|
isKeyType(bytes32(msg.sender), ACTION_KEY)
|
2018-02-22 08:05:10 +00:00
|
|
|
);
|
2018-02-21 21:17:38 +00:00
|
|
|
_;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-02-21 21:17:38 +00:00
|
|
|
function Identity() public {
|
2018-02-26 21:26:14 +00:00
|
|
|
_addKey(bytes32(msg.sender), MANAGEMENT_KEY, 0);
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-02 19:00:46 +00:00
|
|
|
minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] = 1;
|
|
|
|
minimumApprovalsByKeyPurpose[ACTION_KEY] = 1;
|
2018-02-21 21:17:38 +00:00
|
|
|
}
|
2018-02-27 21:11:22 +00:00
|
|
|
|
2018-03-02 14:32:00 +00:00
|
|
|
function managerReset(address _newKey)
|
|
|
|
external
|
|
|
|
recoveryOnly
|
|
|
|
{
|
2018-03-02 19:00:46 +00:00
|
|
|
recoveryManager = _newKey;
|
|
|
|
_addKey(bytes32(recoveryManager), MANAGEMENT_KEY, 0);
|
|
|
|
minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] = keysByPurpose[MANAGEMENT_KEY].length;
|
2018-03-02 14:32:00 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 19:00:46 +00:00
|
|
|
function processManagerReset(uint256 limit)
|
|
|
|
public
|
2018-03-02 14:32:00 +00:00
|
|
|
{
|
2018-03-02 19:00:46 +00:00
|
|
|
require(recoveryManager != address(0));
|
|
|
|
bytes32 newKey = bytes32(recoveryManager);
|
2018-03-02 14:32:00 +00:00
|
|
|
bytes32[] memory managers = keysByPurpose[MANAGEMENT_KEY];
|
2018-03-02 19:00:46 +00:00
|
|
|
uint256 totalManagers = managers.length;
|
|
|
|
|
2018-03-02 14:32:00 +00:00
|
|
|
if (limit == 0) {
|
|
|
|
limit = totalManagers;
|
|
|
|
}
|
2018-03-02 19:00:46 +00:00
|
|
|
|
|
|
|
minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] = totalManagers - limit + 1;
|
|
|
|
for (uint256 i = 0; i < limit; i++) {
|
|
|
|
bytes32 manager = managers[i];
|
2018-03-02 14:32:00 +00:00
|
|
|
if (manager != newKey) {
|
|
|
|
_removeKey(manager, MANAGEMENT_KEY);
|
|
|
|
totalManagers--;
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 19:00:46 +00:00
|
|
|
|
2018-03-02 14:32:00 +00:00
|
|
|
if (totalManagers == 1) {
|
2018-03-02 19:00:46 +00:00
|
|
|
recoveryManager = address(0);
|
2018-03-02 14:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function addKey(
|
|
|
|
bytes32 _key,
|
|
|
|
uint256 _purpose,
|
|
|
|
uint256 _type
|
|
|
|
)
|
|
|
|
public
|
2018-02-22 08:16:06 +00:00
|
|
|
selfOnly
|
2018-02-22 08:05:10 +00:00
|
|
|
returns (bool success)
|
2018-03-02 14:32:00 +00:00
|
|
|
{
|
2018-02-21 21:17:38 +00:00
|
|
|
_addKey(_key, _purpose, _type);
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-03-02 14:32:00 +00:00
|
|
|
function replaceKey(
|
|
|
|
bytes32 _oldKey,
|
|
|
|
bytes32 _newKey,
|
|
|
|
uint256 _newType
|
|
|
|
)
|
|
|
|
public
|
|
|
|
selfOnly
|
|
|
|
returns (bool success)
|
|
|
|
{
|
2018-03-02 19:00:46 +00:00
|
|
|
uint256 purpose = keys[_oldKey].purpose;
|
2018-03-02 14:32:00 +00:00
|
|
|
_addKey(_newKey, purpose, _newType);
|
|
|
|
_removeKey(_oldKey, purpose);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function removeKey(
|
|
|
|
bytes32 _key,
|
|
|
|
uint256 _purpose
|
|
|
|
)
|
|
|
|
public
|
2018-02-22 08:16:06 +00:00
|
|
|
selfOnly
|
2018-02-22 08:05:10 +00:00
|
|
|
returns (bool success)
|
|
|
|
{
|
2018-02-21 21:17:38 +00:00
|
|
|
_removeKey(_key, _purpose);
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function execute(
|
|
|
|
address _to,
|
|
|
|
uint256 _value,
|
|
|
|
bytes _data
|
|
|
|
)
|
2018-02-21 21:17:38 +00:00
|
|
|
public
|
2018-02-26 22:22:04 +00:00
|
|
|
managerOrActor(bytes32(msg.sender))
|
2018-02-21 21:17:38 +00:00
|
|
|
returns (uint256 executionId)
|
|
|
|
{
|
2018-02-23 17:02:53 +00:00
|
|
|
executionId = _execute(_to, _value, _data);
|
2018-02-22 08:19:38 +00:00
|
|
|
approve(executionId, true);
|
2018-02-21 21:17:38 +00:00
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-03-03 02:48:15 +00:00
|
|
|
function approve(uint256 _id, bool _approval)
|
2018-02-21 21:17:38 +00:00
|
|
|
public
|
2018-02-26 22:22:04 +00:00
|
|
|
managerOrActor(bytes32(msg.sender))
|
2018-02-21 21:17:38 +00:00
|
|
|
returns (bool success)
|
|
|
|
{
|
2018-03-03 02:48:15 +00:00
|
|
|
return _approve(bytes32(msg.sender), _id, _approval);
|
2018-02-26 21:26:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 15:42:44 +00:00
|
|
|
function setMinimumApprovalsByKeyType(
|
2018-03-02 19:00:46 +00:00
|
|
|
uint256 _purpose,
|
|
|
|
uint256 _minimumApprovals
|
2018-02-22 08:16:06 +00:00
|
|
|
)
|
|
|
|
public
|
|
|
|
selfOnly
|
|
|
|
{
|
2018-02-28 04:36:48 +00:00
|
|
|
require(_minimumApprovals > 0);
|
2018-03-02 19:00:46 +00:00
|
|
|
require(_minimumApprovals <= keysByPurpose[_purpose].length);
|
|
|
|
minimumApprovalsByKeyPurpose[_purpose] = _minimumApprovals;
|
2018-02-21 21:17:38 +00:00
|
|
|
}
|
2018-03-02 21:27:08 +00:00
|
|
|
|
2018-03-03 02:54:36 +00:00
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function addClaim(
|
|
|
|
uint256 _claimType,
|
|
|
|
uint256 _scheme,
|
|
|
|
address _issuer,
|
|
|
|
bytes _signature,
|
|
|
|
bytes _data,
|
|
|
|
string _uri
|
|
|
|
)
|
2018-02-21 21:17:38 +00:00
|
|
|
public
|
2018-02-23 17:02:53 +00:00
|
|
|
returns (bytes32 claimHash)
|
2018-02-21 21:17:38 +00:00
|
|
|
{
|
2018-02-23 17:02:53 +00:00
|
|
|
claimHash = keccak256(_issuer, _claimType);
|
|
|
|
if (msg.sender == address(this)) {
|
|
|
|
if (claims[claimHash].claimType > 0) {
|
|
|
|
_modifyClaim(claimHash, _claimType, _scheme, _issuer, _signature, _data, _uri);
|
|
|
|
} else {
|
|
|
|
_includeClaim(claimHash, _claimType, _scheme, _issuer, _signature, _data, _uri);
|
|
|
|
}
|
2018-02-21 21:17:38 +00:00
|
|
|
} else {
|
2018-02-23 17:02:53 +00:00
|
|
|
require(_issuer == msg.sender);
|
|
|
|
require(isKeyType(bytes32(msg.sender), CLAIM_SIGNER_KEY));
|
|
|
|
_execute(address(this), 0, msg.data);
|
2018-02-22 08:05:10 +00:00
|
|
|
ClaimRequested(
|
2018-02-23 17:02:53 +00:00
|
|
|
claimHash,
|
2018-02-22 08:05:10 +00:00
|
|
|
_claimType,
|
|
|
|
_scheme,
|
|
|
|
_issuer,
|
|
|
|
_signature,
|
|
|
|
_data,
|
2018-02-23 17:02:53 +00:00
|
|
|
_uri
|
|
|
|
);
|
2018-01-09 01:00:07 +00:00
|
|
|
}
|
2018-02-21 21:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeClaim(bytes32 _claimId) public returns (bool success) {
|
|
|
|
Claim memory c = claims[_claimId];
|
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
require(
|
|
|
|
msg.sender == c.issuer ||
|
2018-02-23 17:17:57 +00:00
|
|
|
msg.sender == address(this)
|
2018-02-22 08:05:10 +00:00
|
|
|
);
|
2018-02-21 21:17:38 +00:00
|
|
|
|
|
|
|
// MUST only be done by the issuer of the claim, or KEYS OF PURPOSE 1, or the identity itself.
|
|
|
|
// TODO If its the identity itself, the approval process will determine its approval.
|
|
|
|
|
|
|
|
uint claimIdTypePos = indexes[_claimId];
|
|
|
|
delete indexes[_claimId];
|
|
|
|
bytes32[] storage claimsTypeArr = claimsByType[c.claimType];
|
|
|
|
bytes32 replacer = claimsTypeArr[claimsTypeArr.length-1];
|
|
|
|
claimsTypeArr[claimIdTypePos] = replacer;
|
|
|
|
indexes[replacer] = claimIdTypePos;
|
|
|
|
delete claims[_claimId];
|
|
|
|
claimsTypeArr.length--;
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function getKey(
|
|
|
|
bytes32 _key,
|
|
|
|
uint256 _purpose
|
|
|
|
)
|
|
|
|
public
|
|
|
|
constant
|
|
|
|
returns(uint256 purpose, uint256 keyType, bytes32 key)
|
|
|
|
{
|
2018-02-21 21:17:38 +00:00
|
|
|
Key storage myKey = keys[keccak256(_key, _purpose)];
|
|
|
|
return (myKey.purpose, myKey.keyType, myKey.key);
|
|
|
|
}
|
2018-02-21 22:45:25 +00:00
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function isKeyType(bytes32 _key, uint256 _type)
|
|
|
|
public
|
|
|
|
constant
|
|
|
|
returns (bool)
|
|
|
|
{
|
2018-02-21 22:45:25 +00:00
|
|
|
return keys[keccak256(_key, _type)].purpose == _type;
|
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function getKeyPurpose(bytes32 _key)
|
|
|
|
public
|
|
|
|
constant
|
|
|
|
returns(uint256[] purpose)
|
|
|
|
{
|
2018-02-21 21:17:38 +00:00
|
|
|
|
|
|
|
uint256[] memory purposeHolder = new uint256[](4);
|
|
|
|
uint8 counter = 0;
|
|
|
|
|
2018-02-21 22:45:25 +00:00
|
|
|
if (isKeyType(_key, MANAGEMENT_KEY)) {
|
2018-02-21 21:17:38 +00:00
|
|
|
purposeHolder[counter] = MANAGEMENT_KEY;
|
|
|
|
counter++;
|
2018-01-09 01:00:07 +00:00
|
|
|
}
|
2018-02-21 21:17:38 +00:00
|
|
|
|
2018-02-21 22:45:25 +00:00
|
|
|
if (isKeyType(_key, ACTION_KEY)) {
|
2018-02-21 21:17:38 +00:00
|
|
|
purposeHolder[counter] = ACTION_KEY;
|
|
|
|
counter++;
|
2018-01-09 01:00:07 +00:00
|
|
|
}
|
2018-02-21 21:17:38 +00:00
|
|
|
|
2018-02-21 22:45:25 +00:00
|
|
|
if (isKeyType(_key, CLAIM_SIGNER_KEY)) {
|
2018-02-21 21:17:38 +00:00
|
|
|
purposeHolder[counter] = CLAIM_SIGNER_KEY;
|
|
|
|
counter++;
|
2018-01-09 01:00:07 +00:00
|
|
|
}
|
2018-02-21 21:17:38 +00:00
|
|
|
|
2018-02-21 22:45:25 +00:00
|
|
|
if (isKeyType(_key, ENCRYPTION_KEY)) {
|
2018-02-21 21:17:38 +00:00
|
|
|
purposeHolder[counter] = ENCRYPTION_KEY;
|
|
|
|
counter++;
|
2018-01-09 01:00:07 +00:00
|
|
|
}
|
2018-02-21 21:17:38 +00:00
|
|
|
|
|
|
|
uint256[] memory result = new uint256[](counter);
|
2018-02-22 08:05:10 +00:00
|
|
|
for (uint8 i = 0; i < counter; i++) {
|
2018-02-21 21:17:38 +00:00
|
|
|
result[i] = purposeHolder[i];
|
2018-02-22 08:05:10 +00:00
|
|
|
}
|
2018-02-21 21:17:38 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function getKeysByPurpose(uint256 _purpose)
|
|
|
|
public
|
|
|
|
constant
|
2018-03-03 02:48:15 +00:00
|
|
|
returns(bytes32[])
|
2018-02-22 08:05:10 +00:00
|
|
|
{
|
2018-02-21 21:17:38 +00:00
|
|
|
return keysByPurpose[_purpose];
|
|
|
|
}
|
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function getClaim(bytes32 _claimId)
|
|
|
|
public
|
|
|
|
constant
|
|
|
|
returns(uint256 claimType, uint256 scheme, address issuer, bytes signature, bytes data, string uri)
|
|
|
|
{
|
2018-02-21 21:17:38 +00:00
|
|
|
Claim memory _claim = claims[_claimId];
|
|
|
|
return (_claim.claimType, _claim.scheme, _claim.issuer, _claim.signature, _claim.data, _claim.uri);
|
|
|
|
}
|
|
|
|
|
2018-02-22 08:05:10 +00:00
|
|
|
function getClaimIdsByType(uint256 _claimType)
|
|
|
|
public
|
|
|
|
constant
|
|
|
|
returns(bytes32[] claimIds)
|
|
|
|
{
|
2018-02-21 21:17:38 +00:00
|
|
|
return claimsByType[_claimType];
|
2018-01-09 01:00:07 +00:00
|
|
|
}
|
2018-02-26 21:26:14 +00:00
|
|
|
|
2018-03-03 02:48:15 +00:00
|
|
|
modifier validECDSAKey (
|
2018-02-26 21:26:14 +00:00
|
|
|
bytes32 _key,
|
2018-03-03 02:48:15 +00:00
|
|
|
bytes32 _signHash,
|
|
|
|
uint8 _v,
|
|
|
|
bytes32 _r,
|
|
|
|
bytes32 _s
|
|
|
|
)
|
|
|
|
{
|
|
|
|
require(address(_key) == ecrecover(keccak256("\x19Ethereum Signed Message:\n32", _signHash), _v, _r, _s));
|
2018-02-26 22:22:04 +00:00
|
|
|
require(keys[_key].purpose != 0);
|
2018-02-26 21:26:14 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:48:15 +00:00
|
|
|
function approveECDSA(
|
|
|
|
uint256 _id,
|
|
|
|
bool _approval,
|
2018-02-26 21:26:14 +00:00
|
|
|
bytes32 _key,
|
2018-03-03 02:48:15 +00:00
|
|
|
uint8 _v,
|
|
|
|
bytes32 _r,
|
|
|
|
bytes32 _s
|
|
|
|
)
|
2018-02-26 21:26:14 +00:00
|
|
|
public
|
2018-03-03 02:48:15 +00:00
|
|
|
validECDSAKey(
|
|
|
|
_key,
|
|
|
|
keccak256(
|
|
|
|
address(this),
|
|
|
|
bytes4(keccak256("approve(uint256,bool)")),
|
|
|
|
_id,
|
|
|
|
_approval
|
|
|
|
),
|
|
|
|
_v,
|
|
|
|
_r,
|
|
|
|
_s
|
|
|
|
)
|
2018-02-26 22:22:04 +00:00
|
|
|
managerOrActor(_key)
|
2018-02-26 21:26:14 +00:00
|
|
|
returns (bool success)
|
|
|
|
{
|
2018-03-03 02:48:15 +00:00
|
|
|
return _approve(_key, _id, _approval);
|
2018-02-26 21:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function executeECDSA(
|
|
|
|
address _to,
|
|
|
|
uint256 _value,
|
|
|
|
bytes _data,
|
2018-02-26 22:22:04 +00:00
|
|
|
uint _nonce,
|
2018-02-26 21:26:14 +00:00
|
|
|
bytes32 _key,
|
2018-03-03 02:48:15 +00:00
|
|
|
uint8 _v,
|
|
|
|
bytes32 _r,
|
|
|
|
bytes32 _s
|
2018-02-26 21:26:14 +00:00
|
|
|
)
|
|
|
|
public
|
2018-02-28 18:52:32 +00:00
|
|
|
validECDSAKey(_key, keccak256(address(this),
|
|
|
|
bytes4(keccak256("execute(address,uint256,bytes)")),
|
2018-03-03 02:48:15 +00:00
|
|
|
_to, _value, _data, _nonce), _v, _r, _s)
|
2018-02-26 22:22:04 +00:00
|
|
|
managerOrActor(_key)
|
2018-02-26 21:26:14 +00:00
|
|
|
returns (uint256 executionId)
|
|
|
|
{
|
|
|
|
executionId = _execute(_to, _value, _data);
|
2018-03-03 02:48:15 +00:00
|
|
|
_approve(_key, executionId, true);
|
2018-02-26 21:26:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-27 17:23:00 +00:00
|
|
|
function setupRecovery(address _recoveryContract)
|
2018-02-23 19:01:35 +00:00
|
|
|
public
|
2018-02-27 17:23:00 +00:00
|
|
|
selfOnly
|
2018-02-23 19:01:35 +00:00
|
|
|
{
|
2018-03-02 14:32:00 +00:00
|
|
|
require(recoveryContract == address(0));
|
2018-02-27 17:23:00 +00:00
|
|
|
recoveryContract = _recoveryContract;
|
2018-02-23 19:01:35 +00:00
|
|
|
}
|
2018-02-26 21:26:14 +00:00
|
|
|
|
2018-03-01 20:07:32 +00:00
|
|
|
function () public payable {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:54:36 +00:00
|
|
|
function _execute(
|
|
|
|
address _to,
|
|
|
|
uint256 _value,
|
|
|
|
bytes _data
|
|
|
|
)
|
|
|
|
private
|
|
|
|
returns (uint256 executionId)
|
|
|
|
{
|
|
|
|
executionId = nonce;
|
|
|
|
ExecutionRequested(executionId, _to, _value, _data);
|
|
|
|
txx[executionId] = Transaction(
|
|
|
|
{
|
|
|
|
to: _to,
|
|
|
|
value: _value,
|
|
|
|
data: _data,
|
|
|
|
nonce: nonce,
|
|
|
|
approverCount: 0
|
|
|
|
});
|
|
|
|
nonce++;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _approve(
|
|
|
|
bytes32 _key,
|
|
|
|
uint256 _id,
|
|
|
|
bool _approval
|
|
|
|
)
|
|
|
|
private
|
|
|
|
returns(bool success)
|
|
|
|
{
|
|
|
|
|
|
|
|
Transaction storage trx = txx[_id];
|
|
|
|
|
|
|
|
uint256 approvalCount;
|
|
|
|
uint256 requiredKeyPurpose;
|
|
|
|
|
|
|
|
Approved(_id, _approval);
|
|
|
|
|
|
|
|
if (trx.to == address(this)) {
|
|
|
|
require(isKeyType(_key, MANAGEMENT_KEY));
|
|
|
|
bytes32 managerKeyHash = keccak256(_key, MANAGEMENT_KEY);
|
|
|
|
requiredKeyPurpose = MANAGEMENT_KEY;
|
|
|
|
approvalCount = _calculateApprovals(managerKeyHash, _approval, trx);
|
|
|
|
} else {
|
|
|
|
require(isKeyType(_key, ACTION_KEY));
|
|
|
|
bytes32 actorKeyHash = keccak256(_key, ACTION_KEY);
|
|
|
|
requiredKeyPurpose = ACTION_KEY;
|
|
|
|
approvalCount = _calculateApprovals(actorKeyHash, _approval, trx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (approvalCount >= minimumApprovalsByKeyPurpose[requiredKeyPurpose]) {
|
|
|
|
Executed(_id, trx.to, trx.value, trx.data);
|
|
|
|
success = trx.to.call.value(trx.value)(trx.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _addKey(bytes32 _key, uint256 _purpose, uint256 _type) private {
|
|
|
|
bytes32 keyHash = keccak256(_key, _purpose);
|
|
|
|
|
|
|
|
require(keys[keyHash].purpose == 0);
|
|
|
|
require(
|
|
|
|
_purpose == MANAGEMENT_KEY ||
|
|
|
|
_purpose == ACTION_KEY ||
|
|
|
|
_purpose == CLAIM_SIGNER_KEY ||
|
|
|
|
_purpose == ENCRYPTION_KEY
|
|
|
|
);
|
|
|
|
KeyAdded(_key, _purpose, _type);
|
|
|
|
keys[keyHash] = Key(_purpose, _type, _key);
|
|
|
|
indexes[keyHash] = keysByPurpose[_purpose].push(_key) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _removeKey(bytes32 _key, uint256 _purpose) private {
|
|
|
|
|
|
|
|
bytes32 keyHash = keccak256(_key, _purpose);
|
|
|
|
Key storage myKey = keys[keyHash];
|
|
|
|
KeyRemoved(myKey.key, myKey.purpose, myKey.keyType);
|
|
|
|
|
|
|
|
uint index = indexes[keyHash];
|
|
|
|
delete indexes[keyHash];
|
|
|
|
bytes32 replacer = keysByPurpose[_purpose][keysByPurpose[_purpose].length - 1];
|
|
|
|
keysByPurpose[_purpose][index] = replacer;
|
|
|
|
indexes[keccak256(replacer, _purpose)] = index;
|
|
|
|
keysByPurpose[_purpose].length--;
|
|
|
|
|
|
|
|
if (_purpose == MANAGEMENT_KEY) {
|
|
|
|
require(
|
|
|
|
keysByPurpose[MANAGEMENT_KEY].length >= 1 &&
|
|
|
|
keysByPurpose[MANAGEMENT_KEY].length >= minimumApprovalsByKeyPurpose[MANAGEMENT_KEY]
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
delete keys[keyHash];
|
|
|
|
}
|
|
|
|
|
|
|
|
function _calculateApprovals(
|
|
|
|
bytes32 _keyHash,
|
|
|
|
bool _approval,
|
|
|
|
Transaction storage trx
|
|
|
|
)
|
|
|
|
private
|
|
|
|
returns (uint256 approvalCount)
|
|
|
|
{
|
|
|
|
require(trx.approvals[_keyHash] != _approval);
|
|
|
|
|
|
|
|
trx.approvals[_keyHash] = _approval;
|
|
|
|
if (_approval) {
|
|
|
|
trx.approverCount++;
|
|
|
|
} else {
|
|
|
|
trx.approverCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return trx.approverCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _includeClaim(
|
|
|
|
bytes32 _claimHash,
|
|
|
|
uint256 _claimType,
|
|
|
|
uint256 _scheme,
|
|
|
|
address _issuer,
|
|
|
|
bytes _signature,
|
|
|
|
bytes _data,
|
|
|
|
string _uri
|
|
|
|
)
|
|
|
|
private
|
|
|
|
{
|
|
|
|
claims[_claimHash] = Claim(
|
|
|
|
{
|
|
|
|
claimType: _claimType,
|
|
|
|
scheme: _scheme,
|
|
|
|
issuer: _issuer,
|
|
|
|
signature: _signature,
|
|
|
|
data: _data,
|
|
|
|
uri: _uri
|
|
|
|
}
|
|
|
|
);
|
|
|
|
indexes[_claimHash] = claimsByType[_claimType].length;
|
|
|
|
claimsByType[_claimType].push(_claimHash);
|
|
|
|
ClaimAdded(
|
|
|
|
_claimHash,
|
|
|
|
_claimType,
|
|
|
|
_scheme,
|
|
|
|
_issuer,
|
|
|
|
_signature,
|
|
|
|
_data,
|
|
|
|
_uri
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _modifyClaim(
|
|
|
|
bytes32 _claimHash,
|
|
|
|
uint256 _claimType,
|
|
|
|
uint256 _scheme,
|
|
|
|
address _issuer,
|
|
|
|
bytes _signature,
|
|
|
|
bytes _data,
|
|
|
|
string _uri
|
|
|
|
)
|
|
|
|
private
|
|
|
|
{
|
|
|
|
require(msg.sender == _issuer);
|
|
|
|
ClaimChanged(
|
|
|
|
_claimHash,
|
|
|
|
_claimType,
|
|
|
|
_scheme,
|
|
|
|
_issuer,
|
|
|
|
_signature,
|
|
|
|
_data,
|
|
|
|
_uri
|
|
|
|
);
|
|
|
|
claims[_claimHash] = Claim({
|
|
|
|
claimType: _claimType,
|
|
|
|
scheme: _scheme,
|
|
|
|
issuer: _issuer,
|
|
|
|
signature: _signature,
|
|
|
|
data: _data,
|
|
|
|
uri: _uri
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-21 21:17:38 +00:00
|
|
|
}
|
2018-01-09 01:00:07 +00:00
|
|
|
|
|
|
|
|