DidDocumentBuilder API Reference
This document provides a detailed API reference for the DidDocumentBuilder
class — a builder for creating, updating, and resolving DID Documents from raw DID-related messages, typically consumed from Hedera Consensus Service topics.
Class: DidDocumentBuilder
A builder class to construct Decentralized Identifier (DID) Documents by parsing, verifying, and managing DID-related events from a series of messages.
constructor
constructor(messages: string[])
Creates a new instance of DidDocumentBuilder
.
-
messages
(string[], required): Array of raw topic messages containing DID content, typically JSON strings representing DID events.
forDID
forDID(did: string): DidDocumentBuilder
Specifies the DID identifier for which the Document will be built.
-
did
(string, required): The DID string (must be a valid Hedera DID).
-
Throws
DIDError
if the given DID is not a valid Hedera DID.
-
The current
DidDocumentBuilder
instance for chaining.
withVerifier
withVerifier(verifier: Verifier): DidDocumentBuilder
Associates a verifier instance for cryptographic verification of DID messages.
-
verifier
(Verifier, required): An instance capable of verifying message signatures.
-
The current
DidDocumentBuilder
instance for chaining.
build
async build(): Promise<DidDocumentBuilder>
Processes all stored DID-related messages, verifying signatures and handling DID operations (create, update, revoke), building internal DID Document state.
-
Throws
DIDError
if no DID is specified before building (i.e.,forDID
was not called). -
Throws
DIDError
if the DID document does not exist (no valid DIDOwner creation event found).
-
A promise that resolves to the current
DidDocumentBuilder
instance after building.
toDidDocument
toDidDocument(): DIDDocument
Generates the resolved DID Document JSON object according to the internal state built from messages.
-
A
DIDDocument
object representing the constructed DID Document. -
If the DID is deactivated, returns a minimal document without verification or service entries.
toJsonLdDIDDocument
toJsonLdDIDDocument(): JsonLdDIDDocument
Returns the DID Document in JSON-LD format compliant with W3C DID specifications, including standard @context fields.
-
A
JsonLdDIDDocument
including @context and the resolved DID Document properties.
toResolution
toResolution(): DIDResolution
Returns a full DID Resolution result, including the DID Document, document metadata, and resolution metadata.
-
A
DIDResolution
object with the following properties:-
didDocument
: The DID Document in JSON-LD format. -
didDocumentMetadata
: Metadata about creation, update times, and deactivation status. -
didResolutionMetadata
: Metadata describing content type and resolution profile.
-
toDidDocumentCbor
toDidDocumentCbor(): Uint8Array
Encodes the resolved DID Document as CBOR bytes using the CBOR codec.
-
A
Uint8Array
containing the CBOR-encoded DID Document.
from
static from(messages: string[]): DidDocumentBuilder
Static factory method to create a new DidDocumentBuilder
instance from an array of topic messages.
-
messages
(string[], required): Array of raw DID-related messages to initialize the builder.
-
A new instance of
DidDocumentBuilder
.