Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async initCredentialStores() {
if (!this._network_config) {
throw new Error('No common connection profile settings found');
}
const client_config = this._network_config.getClientConfig();
if (client_config && client_config.credentialStore) {
const key_value_store = await BaseClient.newDefaultKeyValueStore(client_config.credentialStore);
this.setStateStore(key_value_store);
const crypto_suite = BaseClient.newCryptoSuite();
// all crypto suites should extends api.CryptoSuite
const cryptoStore = BaseClient.newCryptoKeyStore(client_config.credentialStore.cryptoStore);
crypto_suite.setCryptoKeyStore(cryptoStore);
this.setCryptoSuite(crypto_suite);
} else {
throw new Error('No credentialStore settings found');
}
}
async setAdminSigningIdentity(private_key, certificate, mspid) {
logger.debug('setAdminSigningIdentity - start mspid:%s', mspid);
if (typeof private_key === 'undefined' || private_key === null || private_key === '') {
throw new Error('Invalid parameter. Must have a valid private key.');
}
if (typeof certificate === 'undefined' || certificate === null || certificate === '') {
throw new Error('Invalid parameter. Must have a valid certificate.');
}
if (typeof mspid === 'undefined' || mspid === null || mspid === '') {
throw new Error('Invalid parameter. Must have a valid mspid.');
}
let crypto_suite = this.getCryptoSuite();
if (!crypto_suite) {
crypto_suite = BaseClient.newCryptoSuite();
}
const key = await crypto_suite.createKeyFromRaw(private_key);
const public_key = await crypto_suite.createKeyFromRaw(certificate);
this._adminSigningIdentity = new SigningIdentity(certificate, public_key, mspid, crypto_suite, new Signer(crypto_suite, key));
}