Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/composer-common/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class IdCard {
+ Object getConnectionProfile()
+ Object getCredentials()
+ Object getEnrollmentCredentials()
+ String[] getRoles()
+ Promise fromArchive(Buffer)
}
class IllegalModelException extends BaseFileException {
Expand Down
3 changes: 3 additions & 0 deletions packages/composer-common/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#
Version 0.10.2 {e07efe48c4f431525388c10979b4289b} 2017-07-27
- Added IdCard.getRoles function

Version 0.10.1 {d1fd512551ff5bb30b31f05f6817966e} 2017-07-24
- Added InvalidQueryException, BaseFileException
- Added IdCard to composer-common package
Expand Down
24 changes: 21 additions & 3 deletions packages/composer-common/lib/idcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class IdCard {

/**
* Credentials associated with this card, and which are used to connect to the associated business network.
* @return {Object} credentials in the form <em>{ public: publicKey, private: privateKey }</em>, if they exist.
* <p>
* For PKI-based authentication, the credentials are expected to be of the form:
* <em>{ public: String, private: String }</em>.
* @return {Object} credentials.
*/
getCredentials() {
return this.credentials;
Expand All @@ -105,8 +108,10 @@ class IdCard {
/**
* Enrollment credentials. If there are no credentials associated with this card, these credentials are used to
* enroll with a business network and obtain certificates.
* @return {Object} enrollment credentials in the form <em>{ id: enrollmentId, secret: enrollmentSecret }</em>, if
* they exist.
* <p>
* For an ID/secret enrollment scheme, the credentials are expected to be of the form:
* <em>{ id: String, secret: String }</em>.
* @return {Object} enrollment credentials, if they exist.
*/
getEnrollmentCredentials() {
let result = null;
Expand All @@ -120,6 +125,19 @@ class IdCard {
return result;
}

/**
* Special roles for which this ID can be used, which can include:
* <ul>
* <li>peerAdmin</li>
* <li>channelAdmin</li>
* <li>issuer</li>
* </ul>
* @return {String[]} roles.
*/
getRoles() {
return this.metadata.roles || [ ];
}

/**
* Create an IdCard from a card archive.
* @param {Buffer} buffer - the Buffer to a zip archive
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "hlfv1",
"type": "hlfv1",
"orderers": [
{
"url": "grpcs://",
"cert": "orderer1.crt"
},
{
"url": "grpcs://",
"cert": "orderer2.crt"
}
],
"ca": {
"url": "https://",
"name": "",
"trustedRoots": "",
"verify": true
},
"peers": [
{
"requestURL": "grpcs://",
"eventURL": "grpcs://",
"cert": "peer1.crt"
},
{
"requestURL": "grpcs://",
"eventURL": "grpcs://",
"cert": "peer2.crt"
}
],
"keyValStore": "/YOUR_HOME_DIR/.composer-credentials",
"channel": "composerchannel",
"mspID": "Org1MSP",
"timeout": 300,
"globalcert": "",
"maxSendSize": 10,
"maxRecvSize": 15
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg00IwLLBKoi/9ikb6
ZOAV0S1XeNGWllvlFDeczRKQn2uhRANCAARrvCsQUNRpMUkzFaC7+zV4mClo+beg
4VkUyQR5y5Fle5UVH2GigChWnUoouTO2e2acA/DUuyLDHT0emeBMhoMC
-----END PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEa7wrEFDUaTFJMxWgu/s1eJgpaPm3
oOFZFMkEecuRZXuVFR9hooAoVp1KKLkztntmnAPw1Lsiwx09HpngTIaDAg==
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Conga",
"description": "A valid ID card",
"businessNetwork": "org-acme-biznet",
"image": "images/conga.png",
"roles": [
"peerAdmin",
"channelAdmin",
"issuer"
]
}
58 changes: 53 additions & 5 deletions packages/composer-common/test/idcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,38 +121,51 @@ describe('IdCard', function() {
});
});

it('should load all metadata', function() {
it('should load name', function() {
return readIdCardAsync('valid').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
card.getName().should.equal('Conga');
});
});

it('should load description', function() {
return readIdCardAsync('valid').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
card.getDescription().should.equal('A valid ID card');
});
});

it('should load business network name', function() {
return readIdCardAsync('valid').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
card.getBusinessNetworkName().should.equal('org-acme-biznet');
should.not.exist(card.getEnrollmentCredentials());
});
});

it('should return empty string if no business network name defined', function() {
return readIdCardAsync('minimal').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
card.getBusinessNetworkName().should.be.empty;
card.getBusinessNetworkName().should.be.a('String').that.is.empty;
});
});

it('should return empty string if no description defined', function() {
return readIdCardAsync('minimal').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
card.getDescription().should.be.empty;
card.getDescription().should.be.a('String').that.is.empty;
});
});

it('should load connection profile', function() {
return readIdCardAsync('valid').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
card.getConnectionProfile().should.be.an('Object');
card.getConnectionProfile().should.be.an('Object').that.includes({ name: 'hlfv1' });
});
});

Expand All @@ -166,6 +179,15 @@ describe('IdCard', function() {
});
});

it('should return empty credentials if none defined', function() {
return readIdCardAsync('minimal').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
const credentials = card.getCredentials();
Object.keys(credentials).should.be.empty;
});
});

it('should load enrollment credentials', function() {
return readIdCardAsync('valid-with-enrollment').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
Expand All @@ -176,5 +198,31 @@ describe('IdCard', function() {
});
});

it('should return no enrollment credentials if none defined', function() {
return readIdCardAsync('valid').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
should.not.exist(card.getEnrollmentCredentials());
});
});

it('should load roles', function() {
return readIdCardAsync('valid-with-roles').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
const roles = card.getRoles();
roles.should.have.members(['peerAdmin', 'channelAdmin', 'issuer']);
});
});

it('should return empty roles if none defined', function() {
return readIdCardAsync('valid').then((readBuffer) => {
return IdCard.fromArchive(readBuffer);
}).then((card) => {
const roles = card.getRoles();
roles.should.be.empty;
});
});

});
});