Skip to content

Commit

Permalink
[FAB-9500] Add missing setCryptoKeyStore function
Browse files Browse the repository at this point in the history
Add missing setCryptoKeyStore function to typescript definition

Change-Id: I6fda649d4f82d78c5e275ea34a38a3c48ce4ffcf
Signed-off-by: zhaochy <zhaochy_2015@hotmail.com>
  • Loading branch information
zhaochy1990 committed Apr 16, 2018
1 parent 2d06357 commit 9bc92d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
14 changes: 14 additions & 0 deletions fabric-client/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
};

/**
Expand Down
7 changes: 4 additions & 3 deletions fabric-client/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICryptoKey>;
generateKey(opts: KeyOpts): Promise<ICryptoKey>;
generateKey(opts?: KeyOpts): Promise<ICryptoKey>;
hash(msg: string, opts: any): string;
importKey(pem: string, opts: KeyOpts): ICryptoKey | Promise<ICryptoKey>;
importKey(pem: string, opts?: KeyOpts): ICryptoKey | Promise<ICryptoKey>;
sign(key: ICryptoKey, digest: Buffer): Buffer;
verify(key: ICryptoKey, signature: Buffer, digest: Buffer): boolean;
setCryptoKeyStore(cryptoKeyStore: ICryptoKeyStore): void;
}

export interface UserConfig {
Expand Down
9 changes: 9 additions & 0 deletions test/typescript/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
Peer,
Orderer,
EventHub,
ICryptoSuite,
ICryptoKeyStore,
} from 'fabric-client';
import { IEnrollmentRequest } from 'fabric-ca-client';

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 9bc92d1

Please sign in to comment.