From e66465cbec2a8b36c04b85041d80d7728e4ae137 Mon Sep 17 00:00:00 2001 From: zhaochy Date: Thu, 15 Mar 2018 17:33:00 +0800 Subject: [PATCH] [FAB-8879] add type definition for fabric-ca-client Change-Id: Ice46fd106d30a464faf2c31ece84a4897467d214 Signed-off-by: zhaochy --- fabric-ca-client/index.d.ts | 154 ++++++++++++++++++++++++++++++++++ fabric-ca-client/package.json | 1 + 2 files changed, 155 insertions(+) create mode 100644 fabric-ca-client/index.d.ts diff --git a/fabric-ca-client/index.d.ts b/fabric-ca-client/index.d.ts new file mode 100644 index 0000000000..3017c8ebc8 --- /dev/null +++ b/fabric-ca-client/index.d.ts @@ -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; + getOne(affiliation: string, registrar: User): Promise; + getAll(registrar: User): Promise; + delete(req: IAffiliationRequest, registrar: User): Promise; + update(affiliation: string, req: IAffiliationRequest, registrar: User): Promise; +} + +declare class IdentityService { + create(req: IIdentityRequest, registrar: User): Promise; + getOne(enrollmentID: string, registrar: User): Promise; + getAll(registrar: User): Promise; + delete(enrollmentID: string, registrar: User): Promise; + update(enrollmentID: string, req: IIdentityRequest, registrar: User): Promise; +} + +declare class FabricCAServices extends BaseClient { + constructor(url: string | IFabricCAService, tlsOptions?: TLSOptions, caName?: string, cryptoSuite?: ICryptoSuite); + getCaName(): string; + register(req: IRegisterRequest, registrar: User): Promise; + enroll(req: IEnrollmentRequest); + reenroll(currentUser: User, attr_reqs: IAttributeRequest[]): Promise; + revoke(request: IRevokeRequest, registrar: User): Promise; + generateCRL(request: IRestriction, registrar: User): Promise; + newIdentityService(): IdentityService; + newAffiliationService(): AffiliationService; + toString(): string; +} + +declare module 'fabric-ca-client' { + export = FabricCAServices; +} \ No newline at end of file diff --git a/fabric-ca-client/package.json b/fabric-ca-client/package.json index 3a30439856..e0a8513f13 100644 --- a/fabric-ca-client/package.json +++ b/fabric-ca-client/package.json @@ -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",