Skip to content

Commit

Permalink
[FAB-8879] add type definition for fabric-ca-client
Browse files Browse the repository at this point in the history
Change-Id: Ice46fd106d30a464faf2c31ece84a4897467d214
Signed-off-by: zhaochy <zhaochy_2015@hotmail.com>
  • Loading branch information
zhaochy1990 committed Mar 15, 2018
1 parent 9ad4356 commit e66465c
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
154 changes: 154 additions & 0 deletions fabric-ca-client/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
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 { BaseClient, ICryptoSuite, User } from "fabric-client";

interface TLSOptions {
trustedRoots: Buffer;
verify: boolean;
}

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

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

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

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

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

interface IReEnrollResponse {
key: string;
certificate: string;
rootCertificate: string;
}

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

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

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

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

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

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

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

declare 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'
}

declare 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>;
}

declare 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>;
}

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

declare module 'fabric-ca-client' {
export = FabricCAServices;
}
1 change: 1 addition & 0 deletions fabric-ca-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"node": "^8.9.0",
"npm": "^5.5.1"
},
"types": "./index.d.ts",
"dependencies": {
"bn.js": "^4.11.3",
"elliptic": "^6.2.3",
Expand Down

0 comments on commit e66465c

Please sign in to comment.