Skip to main content
Version: 1.4

Class: CoreDocument

identity_wasm.CoreDocument

A method-agnostic DID Document.

Note: All methods that involve reading from this class may potentially raise an error if the object is being concurrently modified.

Table of contents

Constructors

Methods

Constructors

constructor

new CoreDocument(values)

Creates a new CoreDocument with the given properties.

Parameters

NameType
valuesICoreDocument

Methods

toJSON

toJSON(): Object

  • Return copy of self without private attributes.

Returns

Object

toJSON(): any

Serializes to a plain JS representation.

Returns

any


toString

toString(): string

Return stringified version of self.

Returns

string


id

id(): CoreDID

Returns a copy of the DID Document id.

Returns

CoreDID


setId

setId(id): void

Sets the DID of the document.

Warning

Changing the identifier can drastically alter the results of resolve_method, resolve_service and the related DID URL dereferencing algorithm.

Parameters

NameType
idCoreDID

Returns

void


controller

controller(): CoreDID[]

Returns a copy of the document controllers.

Returns

CoreDID[]


setController

setController(controllers): void

Sets the controllers of the DID Document.

Note: Duplicates will be ignored. Use null to remove all controllers.

Parameters

NameType
controllersnull | CoreDID | CoreDID[]

Returns

void


alsoKnownAs

alsoKnownAs(): string[]

Returns a copy of the document's alsoKnownAs set.

Returns

string[]


setAlsoKnownAs

setAlsoKnownAs(urls): void

Sets the alsoKnownAs property in the DID document.

Parameters

NameType
urlsnull | string | string[]

Returns

void


verificationMethod

verificationMethod(): VerificationMethod[]

Returns a copy of the document's verificationMethod set.

Returns

VerificationMethod[]


authentication

authentication(): (DIDUrl | VerificationMethod)[]

Returns a copy of the document's authentication set.

Returns

(DIDUrl | VerificationMethod)[]


assertionMethod

assertionMethod(): (DIDUrl | VerificationMethod)[]

Returns a copy of the document's assertionMethod set.

Returns

(DIDUrl | VerificationMethod)[]


keyAgreement

keyAgreement(): (DIDUrl | VerificationMethod)[]

Returns a copy of the document's keyAgreement set.

Returns

(DIDUrl | VerificationMethod)[]


capabilityDelegation

capabilityDelegation(): (DIDUrl | VerificationMethod)[]

Returns a copy of the document's capabilityDelegation set.

Returns

(DIDUrl | VerificationMethod)[]


capabilityInvocation

capabilityInvocation(): (DIDUrl | VerificationMethod)[]

Returns a copy of the document's capabilityInvocation set.

Returns

(DIDUrl | VerificationMethod)[]


properties

properties(): Map\<string, any>

Returns a copy of the custom DID Document properties.

Returns

Map\<string, any>


setPropertyUnchecked

setPropertyUnchecked(key, value): void

Sets a custom property in the DID Document. If the value is set to null, the custom property will be removed.

WARNING

This method can overwrite existing properties like id and result in an invalid document.

Parameters

NameType
keystring
valueany

Returns

void


service

service(): Service[]

Returns a set of all Service in the document.

Returns

Service[]


insertService

insertService(service): void

Add a new Service to the document.

Errors if there already exists a service or verification method with the same id.

Parameters

NameType
serviceService

Returns

void


removeService

removeService(didUrl): undefined | Service

Remove a Service identified by the given DIDUrl from the document.

Returns true if the service was removed.

Parameters

NameType
didUrlDIDUrl

Returns

undefined | Service


resolveService

resolveService(query): undefined | Service

Returns the first Service with an id property matching the provided query, if present.

Parameters

NameType
querystring | DIDUrl

Returns

undefined | Service


methods

methods(scope?): VerificationMethod[]

Returns a list of all VerificationMethod in the DID Document, whose verification relationship matches scope.

If scope is not set, a list over the embedded methods is returned.

Parameters

NameType
scope?MethodScope

Returns

VerificationMethod[]


verificationRelationships

verificationRelationships(): (DIDUrl | VerificationMethod)[]

Returns an array of all verification relationships.

Returns

(DIDUrl | VerificationMethod)[]


insertMethod

insertMethod(method, scope): void

Adds a new method to the document in the given scope.

Parameters

NameType
methodVerificationMethod
scopeMethodScope

Returns

void


removeMethod

removeMethod(did): undefined | VerificationMethod

Removes all references to the specified Verification Method.

Parameters

NameType
didDIDUrl

Returns

undefined | VerificationMethod


resolveMethod

resolveMethod(query, scope?): undefined | VerificationMethod

Returns a copy of the first verification method with an id property matching the provided query and the verification relationship specified by scope, if present.

Parameters

NameType
querystring | DIDUrl
scope?MethodScope

Returns

undefined | VerificationMethod


attachMethodRelationship

attachMethodRelationship(didUrl, relationship): boolean

Attaches the relationship to the given method, if the method exists.

Note: The method needs to be in the set of verification methods, so it cannot be an embedded one.

Parameters

NameType
didUrlDIDUrl
relationshipMethodRelationship

Returns

boolean


detachMethodRelationship

detachMethodRelationship(didUrl, relationship): boolean

Detaches the given relationship from the given method, if the method exists.

Parameters

NameType
didUrlDIDUrl
relationshipMethodRelationship

Returns

boolean


verifyJws

verifyJws(jws, options, signatureVerifier?, detachedPayload?): DecodedJws

Decodes and verifies the provided JWS according to the passed options and signatureVerifier. If a signatureVerifier is provided it will be used when verifying decoded JWS signatures, otherwise a default verifier capable of handling the EdDSA, ES256, ES256K algorithms will be used.

Regardless of which options are passed the following conditions must be met in order for a verification attempt to take place.

  • The JWS must be encoded according to the JWS compact serialization.
  • The kid value in the protected header must be an identifier of a verification method in this DID document, or set explicitly in the options.

Parameters

NameType
jwsJws
optionsJwsVerificationOptions
signatureVerifier?IJwsVerifier
detachedPayload?string

Returns

DecodedJws


revokeCredentials

revokeCredentials(serviceQuery, indices): void

If the document has a RevocationBitmap service identified by serviceQuery, revoke all specified indices.

Parameters

NameType
serviceQuerystring | DIDUrl
indicesnumber | number[]

Returns

void


unrevokeCredentials

unrevokeCredentials(serviceQuery, indices): void

If the document has a RevocationBitmap service identified by serviceQuery, unrevoke all specified indices.

Parameters

NameType
serviceQuerystring | DIDUrl
indicesnumber | number[]

Returns

void


clone

clone(): CoreDocument

Deep clones the CoreDocument.

Returns

CoreDocument


_shallowCloneInternal

_shallowCloneInternal(): CoreDocument

Warning

This is for internal use only. Do not rely on or call this method.

Returns

CoreDocument


_strongCountInternal

_strongCountInternal(): number

Warning

This is for internal use only. Do not rely on or call this method.

Returns

number


fromJSON

Static fromJSON(json): CoreDocument

Deserializes an instance from a plain JS representation.

Parameters

NameType
jsonany

Returns

CoreDocument


generateMethod

generateMethod(storage, keyType, alg, fragment, scope): Promise\<string>

Generate new key material in the given storage and insert a new verification method with the corresponding public key material into the DID document.

  • If no fragment is given the kid of the generated JWK is used, if it is set, otherwise an error is returned.
  • The keyType must be compatible with the given storage. Storages are expected to export key type constants for that use case.

The fragment of the generated method is returned.

Parameters

NameType
storageStorage
keyTypestring
algJwsAlgorithm
fragmentundefined | string
scopeMethodScope

Returns

Promise\<string>


purgeMethod

purgeMethod(storage, id): Promise\<void>

Remove the method identified by the fragment from the document and delete the corresponding key material in the storage.

Parameters

NameType
storageStorage
idDIDUrl

Returns

Promise\<void>


createJws

createJws(storage, fragment, payload, options): Promise\<Jws>

Sign the payload according to options with the storage backed private key corresponding to the public key material in the verification method identified by the given `fragment.

Upon success a string representing a JWS encoded according to the Compact JWS Serialization format is returned. See RFC7515 section 3.1.

Parameters

NameType
storageStorage
fragmentstring
payloadstring
optionsJwsSignatureOptions

Returns

Promise\<Jws>


createCredentialJwt

createCredentialJwt(storage, fragment, credential, options, custom_claims?): Promise\<Jwt>

Produces a JWT where the payload is produced from the given credential in accordance with VC Data Model v1.1.

Unless the kid is explicitly set in the options, the kid in the protected header is the id of the method identified by fragment and the JWS signature will be produced by the corresponding private key backed by the storage in accordance with the passed options.

The custom_claims can be used to set additional claims on the resulting JWT.

Parameters

NameType
storageStorage
fragmentstring
credentialCredential
optionsJwsSignatureOptions
custom_claims?Record\<string, any>

Returns

Promise\<Jwt>


createPresentationJwt

createPresentationJwt(storage, fragment, presentation, signature_options, presentation_options): Promise\<Jwt>

Produces a JWT where the payload is produced from the given presentation. in accordance with VC Data Model v1.1.

Unless the kid is explicitly set in the options, the kid in the protected header is the id of the method identified by fragment and the JWS signature will be produced by the corresponding private key backed by the storage in accordance with the passed options.

Parameters

NameType
storageStorage
fragmentstring
presentationPresentation
signature_optionsJwsSignatureOptions
presentation_optionsJwtPresentationOptions

Returns

Promise\<Jwt>


expandDIDJwk

Static expandDIDJwk(did): CoreDocument

Creates a CoreDocument from the given DIDJwk.

Parameters

NameType
didDIDJwk

Returns

CoreDocument