Skip to content

Commit

Permalink
[FAB-8942] fix type definition for 1.1 release
Browse files Browse the repository at this point in the history
Type information in v.1.1.0 is broken and not compilable with tsc.
This CR fix the errors, and add tests with typescript
remove all type definition to 'types' folder

Change-Id: Ia042c94607ab93259872774cd3fb0da60aeb6d05
Signed-off-by: zhaochy <zhaochy_2015@hotmail.com>
  • Loading branch information
zhaochy1990 committed Mar 20, 2018
1 parent 907e33e commit e3f9043
Show file tree
Hide file tree
Showing 16 changed files with 1,329 additions and 625 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ test/fixtures/src/github.com/example_cc/junk.go
*.heapsnapshot
.vscode
.idea
test/typescript/**/*.js
test/typescript/**/*.js.map
4 changes: 3 additions & 1 deletion build/tasks/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const DEPS = [
'fabric-client/lib/msp/identity.js',
'fabric-client/lib/msp/msp.js',
'fabric-client/lib/protos/msp/identities.proto',
'fabric-client/lib/protos/msp/msp_config.proto'
'fabric-client/lib/protos/msp/msp_config.proto',
'fabric-client/types/tsconfig.json',
'fabric-client/types/base.d.ts'
];

gulp.task('ca', function() {
Expand Down
1 change: 1 addition & 0 deletions build/tasks/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gulp.task('lint', function () {
'**/*.js',
'fabric-client/**/*.js',
'fabric-ca-client/lib/*.js',
'!test/typescript/test.js',
'!node_modules/**',
'!fabric-client/node_modules/**',
'!fabric-ca-client/node_modules/**',
Expand Down
9 changes: 8 additions & 1 deletion build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ gulp.task('docker-ready', ['docker-clean'], shell.task([
'docker-compose -f test/fixtures/docker-compose.yaml up -d'
]));

gulp.task('test', ['clean-up', 'lint', 'pre-test', 'docker-ready', 'ca'], function() {
gulp.task('compile', shell.task([
'npm run compile',
], {
verbose: true, // so we can see the docker command output
ignoreErrors: false // once compile failed, throw error
}));

gulp.task('test', ['clean-up', 'lint', 'pre-test', 'compile', 'docker-ready', 'ca'], function() {
// use individual tests to control the sequence they get executed
// first run the ca-tests that tests all the member registration
// and enrollment scenarios (good and bad calls). Then the rest
Expand Down
154 changes: 0 additions & 154 deletions fabric-ca-client/index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion fabric-ca-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"node": "^8.9.0",
"npm": "^5.5.1"
},
"types": "./index.d.ts",
"types": "./types/index.d.ts",
"dependencies": {
"bn.js": "^4.11.3",
"elliptic": "^6.2.3",
Expand Down
189 changes: 189 additions & 0 deletions fabric-ca-client/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
Copyright 2018 IBM All Rights Reserved.
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.
*/

import { ICryptoSuite, ICryptoKeyStore, IKeyValueStore, User } from "fabric-client";
import { BaseClient } from './base';

declare class FabricCAServices extends BaseClient {
constructor(url: string | FabricCAServices.IFabricCAService, tlsOptions?: FabricCAServices.TLSOptions, caName?: string, cryptoSuite?: ICryptoSuite);
getCaName(): string;
register(req: FabricCAServices.IRegisterRequest, registrar: User): Promise<string>;
enroll(req: FabricCAServices.IEnrollmentRequest): Promise<FabricCAServices.IEnrollResponse>;
reenroll(currentUser: User, attr_reqs: FabricCAServices.IAttributeRequest[]): Promise<FabricCAServices.IEnrollResponse>;
revoke(request: FabricCAServices.IRevokeRequest, registrar: User): Promise<any>;
generateCRL(request: FabricCAServices.IRestriction, registrar: User): Promise<any>;
newIdentityService(): FabricCAServices.IdentityService;
newAffiliationService(): FabricCAServices.AffiliationService;
toString(): string;
}


export = FabricCAServices;

declare namespace FabricCAServices {
export interface TLSOptions {
trustedRoots: Buffer;
verify: boolean;
}

export interface IFabricCAService {
url: string;
tlsOptions?: TLSOptions;
caName?: string;
cryptoSuite?: ICryptoSuite;
}

export interface IKeyValueAttribute {
name: string;
value: string;
ecert?: boolean;
}

export interface IRegisterRequest {
enrollmentID: string;
enrollmentSecret?: string;
role?: string;
affiliation: string;
maxEnrollments?: number;
attrs?: IKeyValueAttribute[];
}

export interface IAttributeRequest {
name: string;
optional: boolean;
}

export interface IEnrollmentRequest {
enrollmentID: string;
enrollmentSecret: string;
profile?: string;
attr_reqs?: IAttributeRequest[];
}

export interface IKey {
getSKI(): string;

/**
* Returns true if this key is a symmetric key, false is this key is asymmetric
*
* @returns {boolean} if this key is a symmetric key
*/
isSymmetric(): boolean;

/**
* Returns true if this key is an asymmetric private key, false otherwise.
*
* @returns {boolean} if this key is an asymmetric private key
*/
isPrivate(): boolean;

/**
* Returns the corresponding public key if this key is an asymmetric private key.
* If this key is already public, returns this key itself.
*
* @returns {module:api.Key} the corresponding public key if this key is an asymmetric private key.
* If this key is already public, returns this key itself.
*/
getPublicKey(): IKey;

/**
* Converts this key to its PEM representation, if this operation is allowed.
*
* @returns {string} the PEM string representation of the key
*/
toBytes(): string;
}

export interface IEnrollResponse {
key: IKey;
certificate: string;
rootCertificate: string;
}

export interface IRevokeRequest {
enrollmentID: string;
aki?: string;
serial?: string;
reason?: string;
}

export interface IRestriction {
revokedBefore?: Date;
revokedAfter?: Date;
expireBefore?: Date;
expireAfter?: Date;
}

export interface IIdentityRequest {
enrollmentID: string;
affiliation: string;
attrs?: IKeyValueAttribute[];
type?: string;
enrollmentSecret?: string;
maxEnrollments?: number;
caname?: string;
}

export interface IServiceResponseMessage {
code: number;
message: string;
}

export interface IServiceResponse {
Success: boolean;
Result: any;
Errors: IServiceResponseMessage[];
Messages: IServiceResponseMessage[];
}

export interface IAffiliationRequest {
name: string;
caname?: string;
force?: boolean;
}

export enum HFCAIdentityType {
PEER = 'peer',
ORDERER = 'orderer',
CLIENT = 'client',
USER = 'user'
}

export enum HFCAIdentityAttributes {
HFREGISTRARROLES = 'hf.Registrar.Roles',
HFREGISTRARDELEGATEROLES = 'hf.Registrar.DelegateRoles',
HFREGISTRARATTRIBUTES = 'hf.Registrar.Attributes',
HFINTERMEDIATECA = 'hf.IntermediateCA',
HFREVOKER = 'hf.Revoker',
HFAFFILIATIONMGR = 'hf.AffiliationMgr',
HFGENCRL = 'hf.GenCRL'
}
export class AffiliationService {
create(req: IAffiliationRequest, registrar: User): Promise<IServiceResponse>;
getOne(affiliation: string, registrar: User): Promise<IServiceResponse>;
getAll(registrar: User): Promise<IServiceResponse>;
delete(req: IAffiliationRequest, registrar: User): Promise<IServiceResponse>;
update(affiliation: string, req: IAffiliationRequest, registrar: User): Promise<IServiceResponse>;
}

export class IdentityService {
create(req: IIdentityRequest, registrar: User): Promise<string>;
getOne(enrollmentID: string, registrar: User): Promise<IServiceResponse>;
getAll(registrar: User): Promise<IServiceResponse>;
delete(enrollmentID: string, registrar: User): Promise<IServiceResponse>;
update(enrollmentID: string, req: IIdentityRequest, registrar: User): Promise<IServiceResponse>;
}
}
Loading

0 comments on commit e3f9043

Please sign in to comment.