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( [keyValueStore])

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(BaseClient.newCryptoKeyStore(keyValueStore))
Parameters:
Name Type Argument Description
keyValueStore KeyValueStore <optional>
Optional. The built-in key store saves private keys. The key store must be instance of any KeyValueStore implementations.
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

<async, static> newDefaultKeyValueStore()

Obtains an instance of the KeyValueStore class. By default it returns the built-in implementation InMemoryKeyValueStore.
Returns:
module:api.KeyValueStore instance of the KeyValueStore implementation
Type
KeyValueStore

<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
  • Parameters:
    Name Type Description
    cryptoSuite api.CryptoSuite | ICryptoSuite the CryptoSuite object