Allow each key to only have a single purpose value. This single purpose would actually represent multiple purposes by convention, using bitmasks.
The rationale of this technique is that it would give us the full flexibility and power of having multiple purposes per key, minus the overhead of managing an array of purposes in solidity. Bitmasks can be implemented efficiently in solidity.
I think it would also make more sense to think of keys being set rather than added. You could call setKey
to either add a key or update an existing key.
pragma solidity ^0.4.18;
contract ERC725 {
pragma solidity ^0.4.18;
contract ERC725 {
event KeySet(bytes32 indexed key, uint256 indexed purpose, uint256 indexed keyType);
event KeyRemoved(bytes32 indexed key, uint256 indexed purpose, uint256 indexed keyType);
event ExecutionRequested(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data);
event Executed(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data);
event Approved(uint256 indexed executionId, bool approved);
event KeysRequiredChanged(uint256 purpose, uint256 number);
function getKey(bytes32 _key) public constant returns(uint256 purpose, uint256 keyType, bytes32 key);
function keyHasPurpose(bytes32 _key, uint256 _purpose) public constant returns (bool exists);
function setKey(bytes32 _key, uint256 _purpose, uint256 _keyType) public returns (bool success);
function removeKey(bytes32 _key) public returns (bool success);
function changeKeysRequired(uint256 purpose, uint256 number) external;
function getKeysRequired(uint256 purpose) external view returns(uint256);
function execute(address _to, uint256 _value, bytes _data) public returns (uint256 executionId);
function approve(uint256 _id, bool _approve) public returns (bool success);
}