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 Chain. 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()

Set the current state of this member from a string based JSON object
Returns:
Promise of the unmarshalled Member object represented by the serialized string
Type
Member

getAffiliation()

Get the affiliation.
Returns:
The affiliation.
Type
string

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 CryptoSuite The cryptoSuite.

setEnrollment(privateKey, certificate, mspId)

Set the enrollment object for this User instance
Parameters:
Name Type Description
privateKey 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
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