Skip to content

Instantly share code, notes, and snippets.

@d11e9
Last active November 21, 2015 00:36
Show Gist options
  • Save d11e9/e1b83749e45207fa34aa to your computer and use it in GitHub Desktop.
Save d11e9/e1b83749e45207fa34aa to your computer and use it in GitHub Desktop.
OwnedAttributeStore

##OwnedAttributeStore

This is a proposal for the functioning of a core OwnedAttributeStore contract.

The idea being that the core OwnedAttributeStore contract, can be extended with arbiratry logic as convensions/standards evolve. Allowing it to remain constant while the underlying logic and permissions are updatable. In the primary instance, it would be used as follows (as an example):

  • A OwnedAttributeStore is created. It has an owner (essentially activeKey) attribute by default.
  • A delegatedKeyReset contract is created, and the OwnedAttributeStore's owner attributes' ownership is transfered to the delegated contract.
  • A delegatedKeyRevoker contract is created, and the OwnedAttributeStore's owner attributes' revoker propery is set to the delegated contract.

Essentially all attributes have an owner, writer, revoker and value. All of these being optional.

The only exception is that the OwnedAttributeStore has an owner attribute (essentially activeKey), which is checked in the case that an attribute does not specify an owner (the default).

Pros

  • generic
  • extensible

Yet To be considered/addressed

  • challenge periods and their application
contract OwnedAttributeStore {
struct Attribute {
address owner;
address writer;
address revoker;
bytes32 value;
}
mapping( bytes32 => Attribute ) public attributes;
modifier onlyAttributeOwner(bytes32 attribute) {
if (isAttributeOwner(attribute, msg.sender)) { _ }
}
modifier onlyAttributeOwnerOrWriter(bytes32 attribute) {
if (isAttributeOwner(attribute, msg.sender) || isAttributeWriter(attribute, msg.sender)) { _ }
}
modifier onlyAttributeOwnerOrRevoker(bytes32 attribute) {
if (isAttributeOwner(attribute, msg.sender) || isAttributeRevoker(attribute, msg.sender)) { _ }
}
function OwnedAttributeStore() {
// not using setAttributeAndOwner as 'owner' attribute is special
// and required to be set for onlyAttributeOwner modifier checks.
attributes[bytes32("owner")].owner = msg.sender;
attributes[bytes32("owner")].writer = msg.sender;
attributes[bytes32("owner")].revoker = msg.sender;
attributes[bytes32("owner")].value = bytes32(msg.sender);
}
function isAttributeOwner(bytes32 attribute, address addr) private constant returns(bool) {
bool defaultOwner = attributes[attribute].owner == address(0);
if ((defaultOwner && bytes32(addr) == getAttribute("owner").value)
|| (!defaultOwner && attributes[attribute].owner == addr)) return true;
}
function isAttributeWriter(bytes32 attribute, address addr) private constant returns(bool) {
bool defaultWriter = attributes[attribute].owner == address(0);
if ((defaultWriter && bytes32(addr) == getAttribute("owner").value)
|| (!defaultWriter && attributes[attribute].writer == addr)) return true;
}
function isAttributeRevoker(bytes32 attribute, address addr) private constant returns(bool) {
bool defaultRevoker = attributes[attribute].revoker == address(0);
if ((defaultRevoker && bytes32(addr) == getAttribute("owner").value)
|| (!defaultRevoker && attributes[attribute].revoker == addr)) return true;
}
function getAttribute(bytes32 attribute) private returns (Attribute) { return attributes[attribute]; }
function getAttributeValue(bytes32 attribute) constant public returns(bytes32) { return attributes[attribute].value; }
function setAttributeWriter(bytes32 attribute, address newWriter) onlyAttributeOwner(attribute) {
attributes[attribute].writer = newWriter;
}
function setAttributeRevoker(bytes32 attribute, address newRevoker) onlyAttributeOwner(attribute) {
attributes[attribute].revoker = newRevoker;
}
function setAttributeOwner(bytes32 attribute, address newOwner) onlyAttributeOwner(attribute) {
attributes[attribute].owner = newOwner;
}
function revokeAttribute(bytes32 attribute) onlyAttributeOwnerOrRevoker(attribute) {
attributes[attribute].value = bytes32(0);
}
function setAttribute(bytes32 attribute, bytes32 value) onlyAttributeOwnerOrWriter(attribute) {
attributes[attribute].value = value;
}
function transfer(address newOwner) { setAttributeOwner(bytes32("owner"), newOwner); }
}
@d11e9
Copy link
Author

d11e9 commented Nov 19, 2015

comments welcome 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment