Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 9bc92d1

Browse files
committed
[FAB-9500] Add missing setCryptoKeyStore function
Add missing setCryptoKeyStore function to typescript definition Change-Id: I6fda649d4f82d78c5e275ea34a38a3c48ce4ffcf Signed-off-by: zhaochy <zhaochy_2015@hotmail.com>
1 parent 2d06357 commit 9bc92d1

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

fabric-client/lib/api.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ module.exports.CryptoSuite = class {
155155
* @returns {byte[]} Plain text after decryption
156156
*/
157157
decrypt(key, ciphertext, opts) {if(key||ciphertext||opts);}
158+
159+
/**
160+
* Set the cryptoKeyStore.
161+
*
162+
* When the application needs to use a key store other than the default,
163+
* it should use the {@link Client} newCryptoKeyStore to create an instance and
164+
* use this function to set the instance on the CryptoSuite.
165+
*
166+
* @param {CryptoKeyStore} cryptoKeyStore The cryptoKeyStore.
167+
* @abstract
168+
*/
169+
setCryptoKeyStore(cryptoKeyStore) {
170+
throw new Error('Can\'t call abstract method, must be implemented by sub-class!');
171+
}
158172
};
159173

160174
/**

fabric-client/types/index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ declare namespace Client {
102102

103103
export interface ICryptoSuite {
104104
decrypt(key: ICryptoKey, cipherText: Buffer, opts: any): Buffer;
105-
deriveKey(key: ICryptoKey): ICryptoKey;
105+
deriveKey(key: ICryptoKey, opts?: KeyOpts): ICryptoKey;
106106
encrypt(key: ICryptoKey, plainText: Buffer, opts: any): Buffer;
107107
getKey(ski: string): Promise<ICryptoKey>;
108-
generateKey(opts: KeyOpts): Promise<ICryptoKey>;
108+
generateKey(opts?: KeyOpts): Promise<ICryptoKey>;
109109
hash(msg: string, opts: any): string;
110-
importKey(pem: string, opts: KeyOpts): ICryptoKey | Promise<ICryptoKey>;
110+
importKey(pem: string, opts?: KeyOpts): ICryptoKey | Promise<ICryptoKey>;
111111
sign(key: ICryptoKey, digest: Buffer): Buffer;
112112
verify(key: ICryptoKey, signature: Buffer, digest: Buffer): boolean;
113+
setCryptoKeyStore(cryptoKeyStore: ICryptoKeyStore): void;
113114
}
114115

115116
export interface UserConfig {

test/typescript/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
Peer,
4141
Orderer,
4242
EventHub,
43+
ICryptoSuite,
44+
ICryptoKeyStore,
4345
} from 'fabric-client';
4446
import { IEnrollmentRequest } from 'fabric-ca-client';
4547

@@ -80,6 +82,13 @@ test('test Peer', (t) => {
8082
t.end();
8183
});
8284

85+
test('test-crypto-key-store', (t) => {
86+
const store:ICryptoKeyStore = Client.newCryptoKeyStore();
87+
const cryptoSuite: ICryptoSuite = Client.newCryptoSuite();
88+
cryptoSuite.setCryptoKeyStore(store);
89+
t.end()
90+
})
91+
8392
test('use the connection profile file', (t) => {
8493
const client = Client.loadFromConfig(config_network);
8594
t.pass('Successfully load config from network.yaml');

0 commit comments

Comments
 (0)