Skip to main content

Class: IdentityService

Class which implements the identity contract.

Implements​

  • IIdentityComponent
  • IHealthProviderComponent

Constructors​

Constructor​

new IdentityService(options?): IdentityService

Create a new instance of IdentityService.

Parameters​

options?​

IIdentityServiceConstructorOptions

The options for the service.

Returns​

IdentityService

Throws​

GeneralError if no connectors are registered.

Properties​

CLASS_NAME​

readonly static CLASS_NAME: string

Runtime name for the class.

Methods​

className()​

className(): string

Returns the class name of the component.

Returns​

string

The class name of the component.

Implementation of​

IIdentityComponent.className


start()​

start(): Promise<void>

Register all identity metrics with the telemetry component.

Returns​

Promise<void>

A promise that resolves when all metrics have been registered.

Implementation of​

IIdentityComponent.start


healthApplicationInit()​

healthApplicationInit(contextIds): Promise<void>

Creates a temporary DID document for the application health check.

Parameters​

contextIds​

IContextIds

The context IDs accumulated by prior init steps.

Returns​

Promise<void>

Implementation of​

IHealthProviderComponent.healthApplicationInit


healthApplication()​

healthApplication(callback): Promise<IHealth[] | undefined>

Returns the application health status of the identity service by resolving the DID created in healthApplicationInit.

Parameters​

callback​

HealthApplicationCallback

Callback for deferred results.

Returns​

Promise<IHealth[] | undefined>

The health status of the service.

Implementation of​

IHealthProviderComponent.healthApplication


healthApplicationTeardown()​

healthApplicationTeardown(): Promise<void>

Removes the DID document created in healthApplicationInit.

Returns​

Promise<void>

Implementation of​

IHealthProviderComponent.healthApplicationTeardown


identityCreate()​

identityCreate(namespace?, controller?): Promise<IDidDocument>

Create a new identity.

Parameters​

namespace?​

string

The namespace of the connector to use for the identity, defaults to service configured namespace.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<IDidDocument>

The created identity document.

Implementation of​

IIdentityComponent.identityCreate


identityRemove()​

identityRemove(identity, options?, controller?): Promise<void>

Remove an identity.

Parameters​

identity​

string

The id of the document to remove.

options?​

Optional settings.

removeKeys?​

boolean

Also remove any associated private keys from the vault.

removeDocumentKey?​

boolean

Also remove the document key from the vault.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<void>

A promise that resolves when the identity has been removed.

Implementation of​

IIdentityComponent.identityRemove


verificationMethodCreate()​

verificationMethodCreate(identity, verificationMethodType, verificationMethodId?, controller?): Promise<IDidDocumentVerificationMethod>

Add a verification method to the document in JSON Web key Format.

Parameters​

identity​

string

The id of the document to add the verification method to.

verificationMethodType​

DidVerificationMethodType

The type of the verification method to add.

verificationMethodId?​

string

The id of the verification method, if undefined uses the kid of the generated JWK.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<IDidDocumentVerificationMethod>

The verification method.

Throws​

NotFoundError if the id can not be resolved.

Throws​

NotSupportedError if the platform does not support multiple keys.

Implementation of​

IIdentityComponent.verificationMethodCreate


verificationMethodRemove()​

verificationMethodRemove(verificationMethodId, options?, controller?): Promise<void>

Remove a verification method from the document.

Parameters​

verificationMethodId​

string

The id of the verification method.

options?​

Optional settings.

removeKeys?​

boolean

Also remove any associated private key from the vault.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<void>

A promise that resolves when the verification method has been removed.

Throws​

NotFoundError if the id can not be resolved.

Throws​

NotSupportedError if the platform does not support multiple revocable keys.

Implementation of​

IIdentityComponent.verificationMethodRemove


serviceCreate()​

serviceCreate(identity, serviceId, serviceType, serviceEndpoint, controller?): Promise<IDidService>

Add a service to the document.

Parameters​

identity​

string

The id of the document to add the service to.

serviceId​

string

The id of the service.

serviceType​

string | string[]

The type of the service.

serviceEndpoint​

string | string[]

The endpoint for the service.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<IDidService>

The service.

Throws​

NotFoundError if the id can not be resolved.

Implementation of​

IIdentityComponent.serviceCreate


serviceRemove()​

serviceRemove(serviceId, controller?): Promise<void>

Remove a service from the document.

Parameters​

serviceId​

string

The id of the service.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<void>

A promise that resolves when the service has been removed.

Throws​

NotFoundError if the id can not be resolved.

Implementation of​

IIdentityComponent.serviceRemove


alsoKnownAsAdd()​

alsoKnownAsAdd(documentId, alias, controller?): Promise<void>

Add an alias to the alsoKnownAs property on the document. If the alias is already present the operation is a no-op.

Parameters​

documentId​

string

The id of the document to update.

alias​

string

The alias to add. Must be a Url or Urn (typically another DID).

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<void>

A promise that resolves when the alias has been added.

Throws​

GeneralError if the alias is not a Url or Urn.

Throws​

NotFoundError if the id can not be resolved.

Implementation of​

IIdentityComponent.alsoKnownAsAdd


alsoKnownAsRemove()​

alsoKnownAsRemove(documentId, alias, controller?): Promise<void>

Remove an alias from the alsoKnownAs property on the document. If the alias is not present the operation is a no-op.

Parameters​

documentId​

string

The id of the document to update.

alias​

string

The alias to remove. Must be a Url or Urn.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<void>

A promise that resolves when the alias has been removed.

Throws​

GeneralError if the alias is not a Url or Urn.

Throws​

NotFoundError if the id can not be resolved.

Implementation of​

IIdentityComponent.alsoKnownAsRemove


verifiableCredentialCreate()​

verifiableCredentialCreate(verificationMethodId, id, subject, options?, controller?): Promise<{ verifiableCredential: IDidVerifiableCredential; jwt: string; }>

Create a verifiable credential for a verification method.

Parameters​

verificationMethodId​

string

The verification method id to use.

id​

string | undefined

The id of the credential.

subject​

IJsonLdNodeObject

The credential subject to store in the verifiable credential.

options?​

Additional options for creating the verifiable credential.

revocationIndex?​

number

The bitmap revocation index of the credential, if undefined will not have revocation status.

expirationDate?​

Date

The date the verifiable credential is valid until.

jwtHeaderFields?​

{[id: string]: string; }

Additional fields to include in the JWT header when creating the verifiable credential in jwt format.

jwtPayloadFields?​

{[id: string]: string; }

Additional fields to include in the JWT payload when creating the verifiable credential in jwt format.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<{ verifiableCredential: IDidVerifiableCredential; jwt: string; }>

The created verifiable credential and its token.

Throws​

NotFoundError if the id can not be resolved.

Implementation of​

IIdentityComponent.verifiableCredentialCreate


verifiableCredentialVerify()​

verifiableCredentialVerify(credential): Promise<{ revoked: boolean; verifiableCredential?: IDidVerifiableCredential; }>

Verify a verifiable credential is valid.

Parameters​

credential​

string | IDidVerifiableCredential

The credential to verify.

Returns​

Promise<{ revoked: boolean; verifiableCredential?: IDidVerifiableCredential; }>

The credential stored in the jwt and the revocation status.

Implementation of​

IIdentityComponent.verifiableCredentialVerify


verifiableCredentialRevoke()​

verifiableCredentialRevoke(issuerIdentity, credentialIndex, controller?): Promise<void>

Revoke verifiable credential.

Parameters​

issuerIdentity​

string

The id of the document to update the revocation list for.

credentialIndex​

number

The revocation bitmap index to revoke.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<void>

A promise that resolves when the credential has been revoked.

Implementation of​

IIdentityComponent.verifiableCredentialRevoke


verifiableCredentialUnrevoke()​

verifiableCredentialUnrevoke(issuerIdentity, credentialIndex, controller?): Promise<void>

Unrevoke verifiable credential.

Parameters​

issuerIdentity​

string

The id of the document to update the revocation list for.

credentialIndex​

number

The revocation bitmap index to un revoke.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<void>

A promise that resolves when the credential has been unrevoked.

Implementation of​

IIdentityComponent.verifiableCredentialUnrevoke


verifiablePresentationCreate()​

verifiablePresentationCreate(verificationMethodId, presentationId, contexts, types, verifiableCredentials, options?, controller?): Promise<{ verifiablePresentation: IDidVerifiablePresentation; jwt: string; }>

Create a verifiable presentation from the supplied verifiable credentials.

Parameters​

verificationMethodId​

string

The method to associate with the presentation.

presentationId​

string | undefined

The id of the presentation.

contexts​

IJsonLdContextDefinitionRoot | undefined

The contexts for the data stored in the verifiable credential.

types​

string | string[] | undefined

The types for the data stored in the verifiable credential.

verifiableCredentials​

(string | IDidVerifiableCredential)[]

The credentials to use for creating the presentation in jwt format.

options?​

Additional options for creating the verifiable presentation.

expirationDate?​

Date

The date the verifiable presentation is valid until.

jwtHeaderFields?​

{[id: string]: string; }

Additional fields to include in the JWT header when creating the verifiable presentation in jwt format.

jwtPayloadFields?​

{[id: string]: string; }

Additional fields to include in the JWT payload when creating the verifiable presentation in jwt format.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<{ verifiablePresentation: IDidVerifiablePresentation; jwt: string; }>

The created verifiable presentation and its token.

Throws​

NotFoundError if the id can not be resolved.

Implementation of​

IIdentityComponent.verifiablePresentationCreate


verifiablePresentationVerify()​

verifiablePresentationVerify(presentation): Promise<{ revoked: boolean; verifiablePresentation?: IDidVerifiablePresentation; issuers?: IDidDocument[]; }>

Verify a verifiable presentation is valid.

Parameters​

presentation​

string | IDidVerifiablePresentation

The presentation to verify.

Returns​

Promise<{ revoked: boolean; verifiablePresentation?: IDidVerifiablePresentation; issuers?: IDidDocument[]; }>

The presentation stored in the jwt and the revocation status.

Implementation of​

IIdentityComponent.verifiablePresentationVerify


proofCreate()​

proofCreate(verificationMethodId, proofType, unsecureDocument, controller?): Promise<IProof>

Create a proof for a document with the specified verification method.

Parameters​

verificationMethodId​

string

The verification method id to use.

proofType​

ProofTypes

The type of proof to create.

unsecureDocument​

IJsonLdNodeObject

The unsecure document to create the proof for.

controller?​

string

The controller of the identity who can make changes.

Returns​

Promise<IProof>

The proof.

Implementation of​

IIdentityComponent.proofCreate


proofVerify()​

proofVerify(document, proof): Promise<boolean>

Verify proof for a document with the specified verification method.

Parameters​

document​

IJsonLdNodeObject

The document to verify.

proof​

IProof

The proof to verify.

Returns​

Promise<boolean>

True if the proof is verified.

Implementation of​

IIdentityComponent.proofVerify