Skip to content

Commit

Permalink
Clean up the API
Browse files Browse the repository at this point in the history
- clearly define the pluggable APIs in api.js
- generate the doc from Chain.js, Member.js
- move default implementations for KVS, CryptoSuite and MemberService to 'lib/impl'
- fixed path errors

Change-Id: Id2eb657e0cef84e4853766f6056ea79d1beb3004
Signed-off-by: Jim Zhang <jzhang@us.ibm.com>
  • Loading branch information
jimthematrix committed Oct 3, 2016
1 parent c0ea692 commit c5dd336
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 173 deletions.
7 changes: 5 additions & 2 deletions build/tasks/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ gulp.task('doc', function () {
'README.md',
'index.js',
'./lib/api.js',
'./lib/FileKeyValueStore.js',
'./lib/impl/FileKeyValueStore.js',
'./lib/impl/CryptoSuite_ECDSA_SHA.js',
'./lib/impl/MemberServices.js',
'./lib/Chain.js',
'./lib/Member.js'
'./lib/Member.js',
'./lib/X509Certificate.js'
], {read: false})
.pipe(jsdoc())
.pipe(gulp.dest('./docs/gen'));
Expand Down
24 changes: 12 additions & 12 deletions lib/Chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,26 @@

'use strict';

/**
* This module contains the implementation of the [Chain]{@link module:api.Chain} abstract class.
*
* @module Chain
*/

var api = require('./api.js');
var utils = require('./utils.js');
var urlParser = require('url');
var net = require('net');
var util = require('util');
var MemberServices = require('./MemberServices.js');
var MemberServices = require('./impl/MemberServices.js');
var Member = require('./Member.js');

/**
* The class representing a chain with which the client SDK interacts.
*
* @class Chain
* @memberof module:Chain
* @class
*/
module.exports = class extends api.Chain {
var Chain = class {

/**
* @param {string} name to identify different chain instances. The naming of chain instances
* is completely at the client application's discretion.
*/
constructor(name) {
super();

// Name of the chain is only meaningful to the client
this._name = '';

Expand Down Expand Up @@ -80,6 +71,13 @@ module.exports = class extends api.Chain {
// emitting events. This will be removed when the SDK is able to receive events from the
this._deployWaitTime = 20;
this._invokeWaitTime = 5;

/**
* @member [CryptoSuite]{@link module:api.CryptoSuite} cryptoPrimitives The crypto primitives object provides access to the crypto suite
* for functions like sign, encrypt, decrypt, etc.
* @memberof module:api.Chain.prototype
*/
this.cryptoPrimitives = utils.getCryptoSuite();
}

/**
Expand Down Expand Up @@ -362,3 +360,5 @@ module.exports = class extends api.Chain {
}
};

module.exports = Chain;

20 changes: 6 additions & 14 deletions lib/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

'use strict';

/**
* This module defines the implementations for the [Member]{@link module:api.Member} class
* plus auxiliary classes for handling TCert downloads from the member services
*
* @module Member
*/

var api = require('./api.js');
var util = require('util');
var stats = require('./stats.js');
Expand All @@ -40,19 +33,15 @@ var stats = require('./stats.js');
* - enrolled: the user has used the one-time password to exchange for an Enrollment Certificate (ECert)
* which can be used to identify him/herself to the member services
*
* @class Member
* @memberof module:Member
* @class
*/
module.exports = class extends api.Member {
var Member = class {

/**
* Constructor for a member.
* @param cfg {string | RegistrationRequest} The member name or registration request.
* @returns {Member} A member who is neither registered nor enrolled.
*/
constructor(cfg, chain) {
super();

if (util.isString(cfg)) {
this._name = cfg;
this._roles = null; //string[]
Expand Down Expand Up @@ -85,7 +74,7 @@ module.exports = class extends api.Member {

/**
* Get the chain.
* @returns {Chain} The chain.
* @returns [Chain]{@link Chain} The chain.
*/
getChain() {
return this._chain;
Expand Down Expand Up @@ -360,3 +349,6 @@ function toKeyValueStoreName(name) {
return 'member.' + name;
}

module.exports = Member;


12 changes: 11 additions & 1 deletion lib/X509Certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ var api = require('./api.js');
var utils = require('./utils.js');
var certPaser = require('./utils-x509cert.js');

var X509Certificate = class extends api.X509Certificate {
/**
* A model to represent x.509 certificate
*
* @class
*/
var X509Certificate = class {

constructor(buffer) {
debug('cert:', JSON.stringify(buffer));
Expand All @@ -38,6 +43,11 @@ var X509Certificate = class extends api.X509Certificate {
}
}

/**
* What would be a suitable description of this method?
*
* @param {Object} Object ID
*/
criticalExtension(oid) {
var ext;
debug('oid: ', oid);
Expand Down
Loading

0 comments on commit c5dd336

Please sign in to comment.