-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ChronoBank/release/release-0.1.0Release/re…
…lease 0.1.0
- Loading branch information
Showing
31 changed files
with
8,274 additions
and
3,323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build/* | ||
contracts/* | ||
node_modules/* | ||
.* | ||
*.json | ||
truffle* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module.exports = { | ||
"parser": "babel-eslint", | ||
"extends": "eslint:recommended", | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"mocha": true, | ||
}, | ||
"globals": { | ||
"web3": false, | ||
"artifacts": false, | ||
"assert": false, | ||
"contract": false, | ||
}, | ||
"rules": { | ||
"indent": ["error", "tab"], | ||
|
||
"comma-dangle": ["error", "always"], | ||
"no-cond-assign": ["error", "always"], | ||
"no-await-in-loop": "off", | ||
"block-scoped-var": "error", | ||
"curly": "error", | ||
"eqeqeq": ["error", "always"], | ||
"no-alert": "error", | ||
"no-else-return": ["error", { "allowElseIf": true }], | ||
"no-magic-numbers": ["warn", { "ignoreArrayIndexes": true }], | ||
"no-multi-spaces": ["error", { "exceptions": { "Property": true }}], | ||
"no-restricted-syntax": ["error", "SequenceExpression"], | ||
"no-useless-return": "warn", | ||
"require-await": "warn", | ||
"vars-on-top": "off", | ||
"no-unused-vars": "warn", | ||
"yoda": "error", | ||
|
||
"global-require": "error", | ||
"array-bracket-spacing": ["error", "always", { "singleValue": false, "objectsInArrays": false }], | ||
"block-spacing": ["error", "always"], | ||
"brace-style": ["error", "stroustrup", { "allowSingleLine": false }], | ||
"camelcase": ["error", { "properties": "never" }], | ||
"key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "strict" }], | ||
"keyword-spacing": ["error", { "before": true, "after": true }], | ||
"no-lonely-if": "error", | ||
"no-negated-condition": "error", | ||
"no-trailing-spaces": "error", | ||
"no-whitespace-before-property": "error", | ||
"object-curly-newline": ["error", { "multiline": true, "minProperties": 4 }], | ||
"object-curly-spacing": ["error", "always"], | ||
"object-property-newline": ["warn", { "allowAllPropertiesOnSameLine": true }], | ||
"quote-props": ["warn", "as-needed", { "keywords": true, "numbers": true }], | ||
|
||
"semi": ["error", "never"], | ||
|
||
"arrow-parens": ["error", "as-needed"], | ||
"arrow-spacing": "error", | ||
|
||
"no-duplicate-imports": "error", | ||
"prefer-const": "error", | ||
|
||
"no-undef": "warn", | ||
"no-empty": "warn", | ||
|
||
"no-console": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
contracts/helpers/* | ||
contracts/Migrations.sol | ||
|
||
test/ | ||
migrations/ | ||
.solcover.js | ||
truffle.js | ||
.gitattributes | ||
|
||
.eslint* | ||
.solium* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
test | ||
setup | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"extends": "solium:recommended", | ||
"plugins": [ | ||
"security" | ||
], | ||
"rules": { | ||
"quotes": [ | ||
"error", | ||
"double" | ||
], | ||
"indentation": [ | ||
"error", | ||
4 | ||
], | ||
"security/no-low-level-calls": [ | ||
"error", [ | ||
"callcode" | ||
] | ||
], | ||
"max-line-length": "off", | ||
"security/no-assign-params": "off", | ||
"security/no-inline-assembly": "warning" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
|
||
<a name="0.1.0"></a> | ||
# 0.1.0 (2018-07-17) | ||
- add linters (eslint and solium); | ||
- cover with more tests; | ||
- integrate with MultiEventsHistoryAdapter; | ||
- add migration templates; | ||
- update to the latest dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,87 @@ | ||
# solidity-roles-lib [![Build Status](https://travis-ci.org/ChronoBank/solidity-roles-lib.svg?branch=master)](https://travis-ci.org/ChronoBank/solidity-roles-lib) [![Coverage Status](https://coveralls.io/repos/github/ChronoBank/solidity-roles-lib/badge.svg?branch=master)](https://coveralls.io/github/ChronoBank/solidity-roles-lib?branch=master) | ||
# Roles smart contract library [![Build Status](https://travis-ci.org/ChronoBank/solidity-roles-lib.svg?branch=master)](https://travis-ci.org/ChronoBank/solidity-roles-lib) [![Coverage Status](https://coveralls.io/repos/github/ChronoBank/solidity-roles-lib/badge.svg?branch=master)](https://coveralls.io/github/ChronoBank/solidity-roles-lib?branch=master) | ||
|
||
Part of [LaborX project](https://github.com/ChronoBank). Provides a couple of smart contracts to set up role-based access to system's contracts. | ||
|
||
- **Roles2Library** - smart contract that is a foundation of roles-based system, organizes access to functions in secured way; | ||
- **Roles2LibraryAdapter** - basic contract that is intended to store a reference to a roles2Library and contains protection modifier to guard functions for role-based access. | ||
|
||
## Installation | ||
|
||
Organized as npm package this smart contracts could be easily added to a project by | ||
|
||
```bash | ||
npm install -s solidity-roles-lib | ||
``` | ||
|
||
## Usage | ||
|
||
Right before you decided to use them add this library to package dependencies and import any contract according to this pattern, for example: | ||
|
||
```javascript | ||
import "solidity-shared-lib/contracts/Roles2Library.sol"; | ||
``` | ||
|
||
or | ||
|
||
```javascript | ||
import "solidity-shared-lib/contracts/Roles2LibraryAdapter.sol"; | ||
``` | ||
|
||
Cause you might want to use **Roles2Library** without any changes (if you want to then skip this paragraph), you will need to deploy this contract. But due to imperfection of **truffle** framework when you write in migration files `const Roles2Library = artifacts.require("Roles2Library")` this artifact will not be found. You have two options: | ||
1. Inherit from _Roles2Library_ and **truffle** will automatically grap contract's artifact; | ||
2. Create a solidity file, for example, **Imports.sol** and add an `import` statement of _Roles2Library_. (I would recommend this one because it will not produce one more contract name and looks more reasonable.) | ||
|
||
## Details | ||
|
||
Contracts that wants to adopt storage approach should do the following: | ||
|
||
1. Define a contract that will inherit from **Roles2LibraryAdapter** contract and implement constructor: | ||
|
||
```javascript | ||
contract JobsController is Roles2LibraryAdapter { | ||
|
||
constructor(address _roles2Library) Roles2LibraryAdapter(_roles2Library) public { | ||
// TODO: initialization here | ||
} | ||
//... | ||
} | ||
``` | ||
|
||
3. Protect any of your functions with `auth` modifier to restrict an access to only authorized members: | ||
|
||
```javascript | ||
//... | ||
function actionExample() external auth returns (uint) { | ||
//... | ||
} | ||
//... | ||
``` | ||
|
||
4. In your migrations or during contracts set up organize rules (roles) that should be able to access your protected functions. For more details look at **Roles2Library** documentation and migration templates. | ||
|
||
```javascript | ||
const Roles = { | ||
ADMIN: 2, | ||
MODERATOR: 4, | ||
USER: 11, | ||
} | ||
|
||
const jobController = await JobsController.deployed() | ||
// Allow only defined role to call protected function | ||
const sig = jobsController.contract.actionExample.getData().slice(0, 10) | ||
await roles2Library.addRoleCapability(Roles.ADMIN, jobsController.address, sig) | ||
//... | ||
|
||
``` | ||
|
||
## Migrations | ||
|
||
Migration templates are presented in `./migrations_templates` folder so you can use them as a scaffolding for your own configuration. Basic scenarios covered by migration templates are: | ||
|
||
- deploying and initializing _Roles2Library_ contract; | ||
- deploying user's smart contract which is inherited from _Roles2LibraryAdapter_ contract; | ||
- setuping role rules for user's contract | ||
|
||
--- | ||
|
||
For more information and use cases look at tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
const errorScope = { | ||
roles: 20000 | ||
} | ||
const errorScope = { roles: 20000, } | ||
|
||
const errorCodes = { | ||
UNAUTHORIZED: 0, | ||
OK: 1, | ||
UNAUTHORIZED: 0, | ||
OK: 1, | ||
|
||
ROLES_ALREADY_EXISTS: errorScope.roles + 1, | ||
ROLES_INVALID_INVOCATION: errorScope.roles + 2, | ||
ROLES_NOT_FOUND: errorScope.roles + 3 | ||
ROLES_ALREADY_EXISTS: errorScope.roles + 1, | ||
ROLES_INVALID_INVOCATION: errorScope.roles + 2, | ||
ROLES_NOT_FOUND: errorScope.roles + 3, | ||
} | ||
|
||
module.exports = errorCodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.