Skip to content

Class: VerifiableCredentialsServiceBase

modules/verifiable-credentials.VerifiableCredentialsServiceBase

Service responsible for managing verifiable credentials and presentations. You can read more about verifiable credentials data model here.

const { verifiableCredentialsService } = await initWithPrivateKeySigner(privateKey, rpcUrl);
verifiableCredentialsService.createRoleVC(...);

Table of contents

Constructors

Methods

Constructors

constructor

new VerifiableCredentialsServiceBase(_signerService, _cacheClient)

Parameters

Name Type
_signerService SignerService
_cacheClient CacheClient

Methods

continueExchange

continueExchange(«destructured»): Promise<undefined | VerifiablePresentation | VpRequest>

Parameters

Name Type
«destructured» ContinueExchangeCredentials<RoleCredentialSubject>

Returns

Promise<undefined | VerifiablePresentation | VpRequest>

issued credentials or request of additional credentials

Description

Sends credentials requested by issuer and returns either issued credentials or next credentials request


createCredential

createCredential(params): Credential<RoleCredentialSubject>

Create a credential with given parameters.

await verifiableCredentialsService.createCredential({
    id: 'did:ethr:ewc:0x...00',
    namespace: 'root.energyweb.iam.ewc',
    version: '1',
    issuerFields: [],
    expirationDate: new Date(),
});

Parameters

Name Type Description
params RoleCredentialSubjectParams verifiable credential parameters

Returns

Credential<RoleCredentialSubject>

Energy Web credential


createPresentation

createPresentation(verifiableCredential, options?): Presentation

Create a presentation with given verifiable credentials. Allow create presentation for a given presentation definition.

verifiableCredentialsService.createPresentation([...credentials]);

Parameters

Name Type Description
verifiableCredential VerifiableCredential<RoleCredentialSubject>[] role credential parameters
options? CreatePresentationParams presentation options

Returns

Presentation

presentation


createRoleVC

createRoleVC(credentialParams, proofOptions?): Promise<VerifiableCredential<RoleCredentialSubject>>

Parameters

Name Type
credentialParams RoleCredentialSubjectParams
proofOptions? ProofOptions

Returns

Promise<VerifiableCredential<RoleCredentialSubject>>


createVerifiablePresentation

createVerifiablePresentation(verifiableCredential, options?): Promise<VerifiablePresentation>

Create a verifiable presentation with given verifiable credentials and EIP712 signature.

verifiableCredentialsService.createVerifiablePresentation([...credentials]);

Parameters

Name Type Description
verifiableCredential VerifiableCredential<RoleCredentialSubject>[] role credential parameters
options? ProofOptions proof options

Returns

Promise<VerifiablePresentation>

verifiable presentation


getCredentialsByDefinition

getCredentialsByDefinition(presentationDefinition): Promise<SelectResults>

Returns issued role verifiable credentials which matches definition.

await verifiableCredentialsService.getCredentialsByDefinition(presentationDefinition);

Parameters

Name Type Description
presentationDefinition IPresentationDefinition credential requirements

Returns

Promise<SelectResults>

results of matching each role verifiable credential to definition


initiateExchange

initiateExchange(options): Promise<ContinueExchangeSelections>

Initialize credential exchange. Only vc-api exchanges currently supported.

verifiableCredentialsService.initiateExchange({
    type: VC_API_EXCHANGE,
    url: 'http://localhost:3000',
});

Parameters

Name Type Description
options ExchangeInvitation object with options

Returns

Promise<ContinueExchangeSelections>

credentials query with matching verifiable presentations


isRevoked

isRevoked(credential): Promise<boolean>

Check if given verifiable credential is revoked.

await verifiableCredentialsService.isRevoked(credential);

Parameters

Name Type Description
credential VerifiableCredential<RoleCredentialSubject> verifiable credential

Returns

Promise<boolean>

true if credential is revoked


revocationDetails

revocationDetails(credential): Promise<null | CredentialRevocationDetailsResult>

Get the credentials revocation details.

await verifiableCredentialsService.revocationDetails(credential);

Parameters

Name Type Description
credential VerifiableCredential<RoleCredentialSubject> verifiable credential

Returns

Promise<null | CredentialRevocationDetailsResult>

revoker and revocationTimeStamp for the revocation


revokeCredential

revokeCredential(credential): Promise<StatusList2021Credential>

Revoke given verifiable credential with StatusList2021.

await verifiableCredentialsService.revokeCredential(credential);

Parameters

Name Type Description
credential VerifiableCredential<RoleCredentialSubject> verifiable credential

Returns

Promise<StatusList2021Credential>

StatusList2021Credential


verify

verify<T>(vcOrVp, options?): Promise<boolean>

Verify a given credential or presentation. Throws an error if the credential or presentation proof is not valid.

await verifiableCredentialsService.verify(credential);
await verifiableCredentialsService.verify(presentation);

Type parameters

Name Type
T extends ICredentialSubject

Parameters

Name Type Description
vcOrVp VerifiablePresentation | VerifiableCredential<T> verifiable presentation or credential
options? ProofOptions proof options

Returns

Promise<boolean>

true if the proof is valid


create

Static create(signerService, cacheClient): Promise<VerifiableCredentialsServiceBase>

Parameters

Name Type
signerService SignerService
cacheClient CacheClient

Returns

Promise<VerifiableCredentialsServiceBase>