From 9bc92d1177b88fd5388a9be86787cc7d32e48661 Mon Sep 17 00:00:00 2001 From: zhaochy Date: Mon, 16 Apr 2018 15:28:39 +0800 Subject: [PATCH] [FAB-9500] Add missing setCryptoKeyStore function Add missing setCryptoKeyStore function to typescript definition Change-Id: I6fda649d4f82d78c5e275ea34a38a3c48ce4ffcf Signed-off-by: zhaochy --- fabric-client/lib/api.js | 14 ++++++++++++++ fabric-client/types/index.d.ts | 7 ++++--- test/typescript/test.ts | 9 +++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/fabric-client/lib/api.js b/fabric-client/lib/api.js index 928d6b2fb2..51743ea45a 100755 --- a/fabric-client/lib/api.js +++ b/fabric-client/lib/api.js @@ -155,6 +155,20 @@ module.exports.CryptoSuite = class { * @returns {byte[]} Plain text after decryption */ decrypt(key, ciphertext, opts) {if(key||ciphertext||opts);} + + /** + * Set the cryptoKeyStore. + * + * When the application needs to use a key store other than the default, + * it should use the {@link Client} newCryptoKeyStore to create an instance and + * use this function to set the instance on the CryptoSuite. + * + * @param {CryptoKeyStore} cryptoKeyStore The cryptoKeyStore. + * @abstract + */ + setCryptoKeyStore(cryptoKeyStore) { + throw new Error('Can\'t call abstract method, must be implemented by sub-class!'); + } }; /** diff --git a/fabric-client/types/index.d.ts b/fabric-client/types/index.d.ts index 6de885f2a4..dbbdc41a63 100644 --- a/fabric-client/types/index.d.ts +++ b/fabric-client/types/index.d.ts @@ -102,14 +102,15 @@ declare namespace Client { export interface ICryptoSuite { decrypt(key: ICryptoKey, cipherText: Buffer, opts: any): Buffer; - deriveKey(key: ICryptoKey): ICryptoKey; + deriveKey(key: ICryptoKey, opts?: KeyOpts): ICryptoKey; encrypt(key: ICryptoKey, plainText: Buffer, opts: any): Buffer; getKey(ski: string): Promise; - generateKey(opts: KeyOpts): Promise; + generateKey(opts?: KeyOpts): Promise; hash(msg: string, opts: any): string; - importKey(pem: string, opts: KeyOpts): ICryptoKey | Promise; + importKey(pem: string, opts?: KeyOpts): ICryptoKey | Promise; sign(key: ICryptoKey, digest: Buffer): Buffer; verify(key: ICryptoKey, signature: Buffer, digest: Buffer): boolean; + setCryptoKeyStore(cryptoKeyStore: ICryptoKeyStore): void; } export interface UserConfig { diff --git a/test/typescript/test.ts b/test/typescript/test.ts index 976d6ae2d4..e72a03bf5c 100644 --- a/test/typescript/test.ts +++ b/test/typescript/test.ts @@ -40,6 +40,8 @@ import { Peer, Orderer, EventHub, + ICryptoSuite, + ICryptoKeyStore, } from 'fabric-client'; import { IEnrollmentRequest } from 'fabric-ca-client'; @@ -80,6 +82,13 @@ test('test Peer', (t) => { t.end(); }); +test('test-crypto-key-store', (t) => { + const store:ICryptoKeyStore = Client.newCryptoKeyStore(); + const cryptoSuite: ICryptoSuite = Client.newCryptoSuite(); + cryptoSuite.setCryptoKeyStore(store); + t.end() +}) + test('use the connection profile file', (t) => { const client = Client.loadFromConfig(config_network); t.pass('Successfully load config from network.yaml');