Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Added network to show using ACLs (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
dselman authored and Simon Stone committed Jul 3, 2017
1 parent 8b758a5 commit dc3cdc9
Show file tree
Hide file tree
Showing 16 changed files with 726 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/pii-network/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage
dist
go
lib
node_modules
out
48 changes: 48 additions & 0 deletions packages/pii-network/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
env:
es6: true
node: true
mocha: true
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 2015
sourceType:
- script
rules:
indent:
- error
- 4
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
no-unused-vars:
- error
- args: none
no-console: off
curly: error
eqeqeq: error
no-throw-literal: error
strict: error
no-var: error
dot-notation: error
no-tabs: error
no-trailing-spaces: error
no-use-before-define: error
no-useless-call: error
no-with: error
operator-linebreak: error
require-jsdoc:
- error
- require:
ClassDeclaration: true
MethodDefinition: true
FunctionDeclaration: true
valid-jsdoc:
- error
- requireReturn: false
yoda: error
50 changes: 50 additions & 0 deletions packages/pii-network/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# JSDoc
out

# Mac files.
**/.DS_Store

*.swp

# Build generated files should be ignored by git, but not by npm.
dist

node_modules
48 changes: 48 additions & 0 deletions packages/pii-network/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# JSDoc
out

# Mac files.
**/.DS_Store

*.swp

# Build generated files should be ignored by git, but not by npm.
# dist
3 changes: 3 additions & 0 deletions packages/pii-network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hyperledger Composer Access Control Demo

A business network where members can grant/revoke access to their personal information to other members.
4 changes: 4 additions & 0 deletions packages/pii-network/config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{

"config":""
}
13 changes: 13 additions & 0 deletions packages/pii-network/header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
13 changes: 13 additions & 0 deletions packages/pii-network/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
35 changes: 35 additions & 0 deletions packages/pii-network/jsdoc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc","closure"]
},
"source": {
"include": [
"./lib"
],
"includePattern": ".+\\.js(doc|x)?$"
},
"plugins": ["plugins/markdown"],
"templates": {
"logoFile": "",
"cleverLinks": false,
"monospaceLinks": false,
"dateFormat": "ddd MMM Do YYYY",
"outputSourceFiles": true,
"outputSourcePath": true,
"systemName": "Financial Bond Network",
"footer": "",
"copyright": "Released under the Apache License v2.0",
"navType": "vertical",
"theme": "spacelab",
"linenums": true,
"collapseSymbols": false,
"inverseNav": true,
"protocol": "html://",
"methodHeadingReturns": false
},
"markdown": {
"parser": "gfm",
"hardwrap": true
}
}
50 changes: 50 additions & 0 deletions packages/pii-network/lib/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
env:
node: true
mocha: true
extends: 'eslint:recommended'
parserOptions:
sourceType:
- script
globals:
getAssetRegistry: true
getFactory: true
getParticipantRegistry: true
getCurrentParticipant: true
emit: true
query: true
rules:
indent:
- error
- 4
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
no-unused-vars:
- 0
- args: none
no-console: off
curly: error
eqeqeq: error
no-throw-literal: error
strict: error
dot-notation: error
no-tabs: error
no-trailing-spaces: error
no-useless-call: error
no-with: error
operator-linebreak: error
require-jsdoc:
- error
- require:
ClassDeclaration: true
MethodDefinition: true
FunctionDeclaration: true
yoda: error
no-confusing-arrow: 2
no-constant-condition: 2
90 changes: 90 additions & 0 deletions packages/pii-network/lib/logic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* A Member grants access to their record to another Member.
* @param {org.acme.pii.AuthorizeAccess} authorize - the authorize to be processed
* @transaction
*/
function authorizeAccess(authorize) {

var me = getCurrentParticipant();
console.log('**** AUTH: ' + me.getIdentifier() + ' granting access to ' + authorize.memberId );

if(!me) {
throw new Error('A participant/certificate mapping does not exist.');
}

// if the member is not already authorized, we authorize them
var index = -1;

if(!me.authorized) {
me.authorized = [];
}
else {
index = me.authorized.indexOf(authorize.memberId);
}

if(index < 0) {
me.authorized.push(authorize.memberId);

return getParticipantRegistry('org.acme.pii.Member')
.then(function (memberRegistry) {

// emit an event
var event = getFactory().newEvent('org.acme.pii', 'MemberEvent');
event.memberTransaction = authorize;
emit(event);

// persist the state of the member
return memberRegistry.update(me);
});
}
}

/**
* A Member revokes access to their record from another Member.
* @param {org.acme.pii.RevokeAccess} revoke - the RevokeAccess to be processed
* @transaction
*/
function revokeAccess(revoke) {

var me = getCurrentParticipant();
console.log('**** REVOKE: ' + me.getIdentifier() + ' revoking access to ' + revoke.memberId );

if(!me) {
throw new Error('A participant/certificate mapping does not exist.');
}

// if the member is authorized, we remove them
var index = me.authorized ? me.authorized.indexOf(revoke.memberId) : -1;

if(index>-1) {
me.authorized.splice(index, 1);

return getParticipantRegistry('org.acme.pii.Member')
.then(function (memberRegistry) {

// emit an event
var event = getFactory().newEvent('org.acme.pii', 'MemberEvent');
event.memberTransaction = revoke;
emit(event);

// persist the state of the member
return memberRegistry.update(me);
});
}
}

0 comments on commit dc3cdc9

Please sign in to comment.