Class: BaseClient

BaseClient

Base class for a client that can use a CryptoSuite to sign and hash. It also contains utility methods for constructing new instances of CryptoKeyStore, CryptoSuite and KeyValueStore

new BaseClient()

Methods


<static> addConfigFile(path)

Adds a file to the top of the list of configuration setting files that are part of the hierarchical configuration. These files will override the default settings and be overriden by environment, command line arguments, and settings programmatically set into configuration settings.

The hierarchical configuration settings search order: see BaseClient.getConfigSetting

Parameters:
Name Type Description
path String The path to the file to be added to the top of list of configuration files

<static> getConfigSetting(name, default_value)

Retrieves a setting from the hierarchical configuration and if not found will return the provided default value.

The hierarchical configuration settings search order for a setting aa-bb:
  1. memory: if the setting has been added with
    Client.setConfigSetting('aa-bb', 'value')
  2. Command-line arguments: like
    node app.js --aa-bb value
  3. Environment variables:
    AA_BB=value node app.js
  4. Custom Files: all files added with addConfigFile(path) will be ordered by when added, where same settings in the files added later will override those added earlier
  5. The file located at lib/config/default.json with default settings
Parameters:
Name Type Description
name String The name of a setting
default_value Object The value of a setting if not found in the hierarchical configuration

<static> getLogger(name)

Use this method to get a logger that will add entries to the same location being used by the Hyperledger Fabric client.
Parameters:
Name Type Description
name string The name of the label to be added to the log entries. To help identify the source of the log entry.
Returns:
The logger that may be used to log entires with 'info()', 'warn()', 'error()' and 'debug()' methods to mark the the type of the log entries.
Type
Logger

<static> newCryptoKeyStore(KVSImplClass, opts)

This is a factory method. It returns a new instance of the CryptoKeyStore. When the application needs to use a key store other than the default, it should create a new CryptoKeyStore and set it on the CryptoSuite.

cryptosuite.setCryptoKeyStore(Client.newCryptoKeyStore(KVSImplClass, opts))
Parameters:
Name Type Description
KVSImplClass api.KeyValueStore Optional. The built-in key store saves private keys. The key store may be backed by different KeyValueStore implementations. If specified, the value of the argument must point to a module implementing the KeyValueStore interface.
opts Object Implementation-specific option object used in the constructor
Returns:
a new instance of the CryptoKeystore
Type
CryptoKeyStore

<static> newCryptoSuite(setting)

This is a factory method. It returns a new instance of the CryptoSuite API implementation, based on the "setting" that is passed in, or if skipped, based on default values of the CryptoSetting properties.
Parameters:
Name Type Description
setting CryptoSetting Optional
Returns:
a new instance of the CryptoSuite API implementation
Type
module:api.CryptoSuite

<static> newDefaultKeyValueStore(options)

Obtains an instance of the KeyValueStore class. By default it returns the built-in implementation, which is based on files (FileKeyValueStore). This can be overriden with a configuration setting key-value-store, the value of which is the full path of a CommonJS module for the alternative implementation.
Parameters:
Name Type Description
options Object Specific to the implementation, for initializing the instance. For the built-in file-based implementation, this requires a single property path to the top-level folder for the store
Returns:
A Promise for a module:api.KeyValueStore instance of the KeyValueStore implementation
Type
Promise

<static> normalizeX509(raw)

Fixes a certificate string that may not be in the correct format. Make sure there's a start line with '-----BEGIN CERTIFICATE-----' and end line with '-----END CERTIFICATE-----', so as to be compliant with x509 parsers. Will remove or add required linefeeds and carriage returns.
Parameters:
Name Type Description
raw string a string that contains a X509 certificate
Throws:
An error indicating that the begining and end parts are not correct.
Type
Error

<static> setConfigSetting(name, value)

Adds a setting to override all settings that are part of the hierarchical configuration.

The hierarchical configuration settings search order: see BaseClient.getConfigSetting

Parameters:
Name Type Description
name String The name of a setting
value Object The value of a setting

<static> setLogger(logger)

Configures a logger for the entire SDK to use and override the default logger. Unless this method is called, the SDK uses a default logger based on winston. When using the built-in winston based logger, use the configuration setting hfc-logging to pass in configurations in the following format:

{
  'error': 'error.log',			// 'error' logs are printed to file 'error.log' relative of the current working dir for node.js
  'debug': '/tmp/myapp/debug.log',	// 'debug' and anything more critical ('info', 'warn', 'error') can also be an absolute path
  'info': 'console'			// 'console' is a keyword for logging to console
}

Parameters:
Name Type Description
logger Object a logger instance that defines the following methods: debug(), info(), warn(), error() with string interpolation methods like util.format.

getCryptoSuite()

Returns the CryptoSuite object used by this client instance
Returns:
Type
module:api.CryptoSuite

setCryptoSuite(cryptoSuite)

Sets the client instance to use the CryptoSuite object for signing and hashing Creating and setting a CryptoSuite is optional because the client will construct an instance based on default configuration settings:
  • crypto-hsm: use an implementation for Hardware Security Module (if set to true) or software-based key management (if set to false)
  • crypto-keysize: security level, or key size, to use with the digital signature public key algorithm. Currently ECDSA is supported and the valid key sizes are 256 and 384
  • crypto-hash-algo: hashing algorithm
  • key-value-store: some CryptoSuite implementation requires a key store to persist private keys. A CryptoKeyStore is provided for this purpose, which can be used on top of any implementation of the KeyValueStore interface, such as a file-based store or a database-based one. The specific implementation is determined by the value of this configuration setting.
  • Parameters:
    Name Type Description
    cryptoSuite module:api.CryptoSuite the CryptoSuite object