Giter Club home page Giter Club logo

ds-roles's Introduction

DSRoles

A DSAuthority for up to 256 roles

A role-driven authority for ds-auth which facilitates access to lists of user roles and capabilities. Works as a set of lookup tables for the canCall function to provide boolean answers as to whether a user is authorized to call a given function at given address.

The ability to check permissions in constant time is entirely due to the artificial constraint on the number of roles. 256 was chosen because this lets us abuse the large word size and cheap bitwise operations.

In the context of providing authority for DSAuth, a user is the msg.sender. DSRoles provides 3 different ways of permitting/forbidding function call access to users, with root access being the most permissive:

  1. Root Users - any users added to the _root_users whitelist will be authorized to call any function regardless of what roles or capabilities might be defined.

  2. Public Capabilities - public capabilities are global capabilities which apply to all users and take precedence over any user specific role-capabilities which might be defined.

  3. Role Capabilities - capabilities which are associated with a particular role. Role capabilities are only checked if the user does not have root access and the capability is not public.

Roles are assigned to users by number:

uint8 owner_role = 0;
uint8 user_role = 1;

setUserRole(owner_address, owner_role, true);
setUserRole(user_address, user_role, true);

Capabilities can be assigned to anyone (public) or to a role permitting/forbidding access to a particular function at a given address:

address target = 0x123;  // code address

bytes4 withdraw_sig = bytes4(sha3("withdrawAll()"));
setRoleCapability(owner_role, target, withdraw_sig, true);
setRoleCapability(user_role, target, withdraw_sig, false);

bytes4 deposit_sig = bytes4(sha3("deposit(uint256)"));
setRoleCapability(user_role, target, deposit_sig, true);

Actions

setRootUser

grant root access to a given user (requires auth)

setUserRole

assign a role to given user (requires auth)

setPublicCapability

set public permissions for a given capability (requires auth)

setRoleCapability

set a capability for a given role (requires auth)

ds-roles's People

Contributors

apmilen avatar d-xo avatar desaperados avatar gbalabasquer avatar mbrock avatar mrchico avatar nanexcool avatar nmushegian avatar rainbreak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ds-roles's Issues

allow naming roles

You should be able to name a role (.e.g 0 -> "admin"), then set by name instead of ID

event logging

Currently there is no easy way to audit a ds-roles and see which addresses have which capabilities.

Adding the note modifier would allow an offline tool to reconstruct the authority state.

role toggling

Consider the ability to toggle a role's authentication across all of its functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.