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
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"packages": [
"packages/*"
],
"version": "0.9.2",
"version": "0.10.1",
"hoist": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"name": "composer",
"description": "You must install [Lerna](https://lernajs.io) to build this multi-package repository.",
"version": "0.9.2",
"version": "0.10.1",
"main": "index.js",
"private": true,
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions packages/composer-admin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composer-admin",
"version": "0.9.2",
"version": "0.10.1",
"description": "Hyperledger Composer Admin, code that manages business networks deployed to Hyperledger Fabric",
"engines": {
"node": ">=6",
Expand Down Expand Up @@ -42,9 +42,9 @@
"sinon-as-promised": "^4.0.2"
},
"dependencies": {
"composer-common": "^0.9.2",
"composer-connector-hlf": "^0.9.2",
"composer-connector-hlfv1": "^0.9.2"
"composer-common": "^0.10.1",
"composer-connector-hlf": "^0.10.1",
"composer-connector-hlfv1": "^0.10.1"
},
"license-check-config": {
"src": [
Expand Down
10 changes: 5 additions & 5 deletions packages/composer-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composer-cli",
"version": "0.9.2",
"version": "0.10.1",
"description": "Hyperledger Composer command line interfaces (CLIs)",
"engines": {
"node": ">=6",
Expand Down Expand Up @@ -42,10 +42,10 @@
"dependencies": {
"chalk": "^1.1.3",
"cli-table": "^0.3.1",
"composer-admin": "^0.9.2",
"composer-client": "^0.9.2",
"composer-common": "^0.9.2",
"composer-rest-server": "^0.9.2",
"composer-admin": "^0.10.1",
"composer-client": "^0.10.1",
"composer-common": "^0.10.1",
"composer-rest-server": "^0.10.1",
"homedir": "^0.6.0",
"npm-paths": "^0.1.3",
"nunjucks": "^3.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/composer-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composer-client",
"version": "0.9.2",
"version": "0.10.1",
"description": "The node.js client library for Hyperledger Composer, a development framework for Hyperledger Fabric",
"engines": {
"node": ">=6",
Expand Down Expand Up @@ -42,9 +42,9 @@
"logError": true
},
"dependencies": {
"composer-common": "^0.9.2",
"composer-connector-hlf": "^0.9.2",
"composer-connector-hlfv1": "^0.9.2",
"composer-common": "^0.10.1",
"composer-connector-hlf": "^0.10.1",
"composer-connector-hlfv1": "^0.10.1",
"uuid": "^3.0.1"
},
"devDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions packages/composer-common/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class FileWallet extends Wallet {
+ Promise update(string,string)
+ Promise remove(string)
}
class IdCard {
+ String getName()
+ String getDescription()
+ String getBusinessNetwork()
+ Object getImage()
+ Object getConnection()
+ Map getCredentials()
+ Map getTlsCertificates()
+ Promise fromArchive(Buffer)
}
class BaseModelException extends BaseException {
+ void constructor(string,string,string)
+ string getFileLocation()
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.1 {ac4a5b035d77bfa46eeadf4b312eab8f} 2017-07-21
- Added IdCard to composer-common package

Version 0.9.2 {60327250ee4f059647020f8aee5ed67b} 2017-07-06
- Added includeOptionalFields option to Factory.newXXX functions

Expand Down
207 changes: 207 additions & 0 deletions packages/composer-common/lib/idcard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/*
* 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';

const JSZip = require('jszip');
const path = require('path');

const Logger = require('./log/logger');
const LOG = Logger.getLog('IdCard');

/**
* An ID card.
* @class
* @memberof module:composer-common
*/
class IdCard {

/**
* Create the BusinessNetworkDefinition.
* <p>
* <strong>Note: Only to be called by framework code. Applications should
* retrieve instances from {@link IdCard.fromArchive}</strong>
* @param {Object} metadata - metadata associated with the card.
* @param {Object} connection - connection properties associated with the card.
* @param {Map} credentials - map of credential filename String keys to credential data Buffer objects.
* @param {Map} tlscerts - map of TLS certificate filename String keys to TLS certificate data Buffer objects.
* @private
*/
constructor(metadata, connection, credentials, tlscerts) {
const method = 'constructor';
LOG.entry(method);

this.metadata = metadata;
this.connection = connection;
this.credentials = credentials;
this.tlscerts = tlscerts;

LOG.exit(method);
}

/**
* Name of the card. This is typically used for display purposes, and is not a unique identifier.
* <p>
* This is a mandatory field.
* @return {String} name of the card.
*/
getName() {
return this.metadata.name;
}

/**
* Free text description of the card.
* @return {String} description, or {@link undefined} if none exists.
*/
getDescription() {
return this.metadata.description;
}

/**
* Business network to which the ID card applies. Generally this will be present but may be omitted for system
* cards.
* @return {String} description, or {@link undefined} if none exists.
*/
getBusinessNetwork() {
return this.metadata.businessNetwork;
}

/**
* Image associated with the card.
* @return {Object} an object of the form <i>{ name: imageFileName, data: bufferOfImageData }</i>,
* or {@link undefined} if none exists.
*/
getImage() {
return this.image;
}

/**
* Connection profile for this card.
* @return {Object} connection profile.
*/
getConnection() {
return this.connection;
}

/**
* Credentials associated with this card.
* @return {Map} Map of filename {@link String} keys to {@link Buffer} data.
*/
getCredentials() {
return this.credentials;
}

/**
* TLS certificates used to connect to the business networks.
* @return {Map} Map of filename {@link String} keys to {@link Buffer} data.
*/
getTlsCertificates() {
return this.tlscerts;
}

/**
* Create an IdCard from a card archive.
* @param {Buffer} buffer - the Buffer to a zip archive
* @return {Promise} Promise to the instantiated IdCard
*/
static fromArchive(buffer) {
const method = 'fromArchive';
LOG.entry(method, buffer.length);

return JSZip.loadAsync(buffer).then((zip) => {
let promise = Promise.resolve();

let metadata;
let image;
let connection;
const credentials = new Map();
const tlscerts = new Map();

LOG.debug(method, 'Loading connection.json');
const connectionFile = zip.file('connection.json');
if (!connectionFile) {
throw Error('Required file not found: connection.json');
}

promise = promise.then(() => {
return connectionFile.async('string');
}).then((connectionContent) => {
connection = JSON.parse(connectionContent);
});

LOG.debug(method, 'Loading metadata.json');
const metadataFile = zip.file('metadata.json');
if (!metadataFile) {
throw Error('Required file not found: metadata.json');
}

promise = promise.then(() => {
return metadataFile.async('string');
}).then((metadataContent) => {
metadata = JSON.parse(metadataContent);
if (!metadata.name) {
throw Error('Required meta-data field not found: name');
}

if (metadata.image) {
LOG.debug(method, 'Loading image ' + metadata.image);

const imagePromise = zip.file(metadata.image);
if (!imagePromise) {
throw Error('Image file not found: ' + metadata.image);
}

return imagePromise.async('nodebuffer').then((imageContent) => {
const shortFilename = path.basename(metadata.image);
image = {
name: shortFilename,
data: imageContent
};
});
}
});

const loadDirectoryToMap = function(directoryName, map) {
// Incude '/' following directory name
const fileIndex = directoryName.length + 1;
// Find all files that are direct children of specified directory
const files = zip.file(new RegExp(`^${directoryName}/[^/]+$`));
files && files.forEach((file) => {
promise = promise.then(() => {
return file.async('nodebuffer');
}).then((content) => {
const filename = file.name.slice(fileIndex);
map.set(filename, content);
});
});
};

LOG.debug(method, 'Loading credentials');
loadDirectoryToMap('credentials', credentials);

LOG.debug(method, 'Loading tlscerts');
loadDirectoryToMap('tlscerts', tlscerts);

return promise.then(() => {
const idCard = new IdCard(metadata, connection, credentials, tlscerts);
idCard.image = image;
LOG.exit(method, idCard.toString());
return idCard;
});
});
}

}

module.exports = IdCard;
2 changes: 1 addition & 1 deletion packages/composer-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composer-common",
"version": "0.9.2",
"version": "0.10.1",
"description": "Hyperledger Composer Common, code that is common across client, admin and runtime.",
"engines": {
"node": ">=6",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"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,4 @@
{
"name" : "com.example.cards.Minimal",
"image": "NON_EXISTENT_IMAGE_FILENAME"
}
Loading