Class: User

User

The User class represents users that have been enrolled and represented by an enrollment certificate (ECert) and a signing key. The ECert must have been signed by one of the CAs the blockchain network has been configured to trust. An enrolled user (having a signing key and ECert) can conduct chaincode instantiate, transactions and queries with the Channel. User ECerts can be obtained from a CA beforehand as part of installing and instantiating the application, or it can be obtained from the optional Fabric CA service via its enrollment process. Sometimes User identities are confused with Peer identities. User identities represent signing capability because it has access to the private key, while Peer identities in the context of the application/SDK only has the certificate for verifying signatures. An application cannot use the Peer identity to sign things because the application doesn’t have access to the Peer identity’s private key.

new User(cfg)

Constructor for a member.
Parameters:
Name Type Description
cfg string The member name or an object with the following attributes: - enrollmentID {string}: user name - name {string}: user name, if "enrollmentID" is also specified, the "name" is ignored - roles {string[]}: optional. array of roles - affiliation {string}: optional. affiliation with a group or organization

Methods


fromString(str, no_save)

Set the current state of this member from a string based JSON object
Parameters:
Name Type Description
str string the member state serialized
no_save boolean to indicate that the cryptoSuite should not save
Returns:
Promise of the unmarshalled Member object represented by the serialized string
Type
Member

getAffiliation()

Get the affiliation.
Returns:
The affiliation.
Type
string

getCryptoSuite()

Get the module:api.CryptoSuite cryptoSuite object for this User instance.
Returns:
the cryptoSuite used to store crypto and key store settings
Type
module:api.CryptoSuite

getIdentity()

Get the Identity object for this User instance, used to verify signatures
Returns:
the identity object that encapsulates the user's enrollment certificate
Type
Identity

getName()

Get the member name.
Returns:
The member name.
Type
string

getRoles()

Get the roles.
Returns:
The roles.
Type
Array.<string>

getSigningIdentity()

Get the SigningIdentity object for this User instance, used to generate signatures
Returns:
the identity object that encapsulates the user's private key for signing
Type
SigningIdentity

isEnrolled()

Determine if this name has been enrolled.
Returns:
True if enrolled; otherwise, false.
Type
boolean

setAffiliation(affiliation)

Set the affiliation.
Parameters:
Name Type Description
affiliation string The affiliation.

setCryptoSuite(cryptoSuite)

Set the cryptoSuite. When the application needs to use crypto settings or a key store other than the default, it needs to set a cryptoSuite instance that was created with the desired CryptoSuite settings and CryptoKeyStore options.
Parameters:
Name Type Description
cryptoSuite module:api.CryptoSuite The cryptoSuite.

<async> setEnrollment(privateKey, certificate, mspId, skipPersistence)

Set the enrollment object for this User instance
Parameters:
Name Type Description
privateKey module:api.Key the private key object
certificate string the PEM-encoded string of certificate
mspId string The Member Service Provider id for the local signing identity
skipPersistence boolean Whether to persist this user
Returns:
Promise for successful completion of creating the user's signing Identity
Type
Promise

setRoles(roles)

Set the roles.
Parameters:
Name Type Description
roles Array.<string> The roles.

toString()

Save the current state of this member as a string
Returns:
The state of this member as a string
Type
string