Class

CoreUtils

CoreUtils()

Constructor

# new CoreUtils()

Provides static helper methods to read credentials and keys from disk or raw content, construct Fabric gateway Identities and Signers, and perform common filesystem operations used by the Fabric client tooling.

Core utilities for interacting with files, crypto identities, and Fabric SDK helpers

View Source shared/utils.ts, line 22

Example
// Read an identity and signer from directories
const identity = await CoreUtils.getIdentity('Org1MSP', '/msp/signcerts');
const signer = await CoreUtils.getSigner('/msp/keystore');
// Build a CA user
const user = await CoreUtils.getCAUser('appUser', pemKey, pemCert, 'Org1MSP');

Methods

# async static contentOfLoadFile(contentOrPath, fileReader) → {Promise.<(string|Uint8Array|Buffer)>}

If the input is a Uint8Array or PEM content, returns it as-is; otherwise uses a provided async fileReader to load the content from disk.

Resolve file content from a path or return provided raw content

Parameters:
Name Type Description
contentOrPath string | Uint8Array

Either a raw content buffer/string or a filesystem path

fileReader function

Async function to read file content when a path is provided

View Source shared/utils.ts, line 44

The content to be used downstream

Promise.<(string|Uint8Array|Buffer)>

# async static getCAUser(userName, privateKey, certificate, mspId) → {Promise.<User>}

Constructs a fabric-common User, sets a crypto suite, imports the provided private key, and sets enrollment with certificate and MSP ID.

Create a Fabric CA User object with enrollment

Parameters:
Name Type Description
userName string

The user name for the CA user

privateKey string

PEM-encoded private key

certificate string

PEM-encoded X.509 certificate

mspId string

Membership Service Provider identifier

View Source shared/utils.ts, line 263

The enrolled Fabric User instance

Promise.<User>

# async static getIdentity(mspId, certDirectoryPath) → {Promise.<Identity>}

Reads a certificate from a directory path or accepts raw content and returns an Identity object suitable for the Fabric Gateway.

Build a Fabric Gateway Identity from an MSP ID and certificate

Parameters:
Name Type Description
mspId string

Membership Service Provider ID

certDirectoryPath string

Path to a directory containing the certificate file, or PEM content

View Source shared/utils.ts, line 273

The identity containing mspId and certificate credentials

Promise.<Identity>

# async static readFile(contentOrPath) → {Promise.<(string|Uint8Array|Buffer)>}

Convenience wrapper that loads a file using fs.promises when a path string is provided; otherwise returns the given Buffer directly.

Read file content from a path or return provided Buffer

Parameters:
Name Type Description
contentOrPath string | Buffer

Path to a file on disk or an already-loaded Buffer

View Source shared/utils.ts, line 251

The file content as a Buffer/string depending on reader

Promise.<(string|Uint8Array|Buffer)>