updateDID API Reference
This document provides a concise API reference for the updateDID
function within the Hedera DID SDK for JavaScript.
Function Signature
The updateDID
function allows you to update an existing DID document by providing the DID and an object specifying the desired modifications.
function updateDID(
options: UpdateDIDOptions,
providers: Providers
): Promise<UpdateDIDResult>;
Parameters
The function accepts the following parameters:
-
providers
: (Required) An object encapsulating configuration parameters for interacting with the Hedera network. -
options
: (Required) An object containing the DID to update and the update operations to apply.
providers Parameter
The table below details the structure of the providers
parameter.
Name | Type | Description |
---|---|---|
providers |
|
An object containing a Hedera Client, a cryptographic Signer, and a transaction Publisher (refer to Providers Type for details). |
options Parameter
The table below details the structure of the options
parameter.
Name | Type | Description |
---|---|---|
did |
|
The DID string of the Decentralized Identifier to update. |
updates |
|
A |
privateKey? |
|
A private key (in DER format) or a |
waitForDIDVisibility? |
|
Whether to wait for the DID to be visible on the network. The DID registration transaction may be confirmed before the DID is actually accessible and usable on the network. This option ensures that the function waits until the DID is fully propagated and discoverable. If set to Defaults to |
visibilityTimeoutMs? |
|
The maximum time (in milliseconds) to wait for the DID to be visible on the network. This option is only relevant if |
topicReader? |
|
An instance of a TopicReader responsible for reading messages from the Hedera network topic. |
Data Types
This section elaborates on the data types employed within the providers
parameter.
Providers Type
To utilize this type, at least one of the following must be defined: client
or publisher
. If both are provided, publisher
takes precedence.
The table below provides a detailed description of the Providers
type.
Name | Type | Description |
---|---|---|
clientOptions? |
|
Configuration options for instantiating a Hedera Client. See a full running example in the source code. |
client? |
|
An instance of a Hedera Client. See a full running example in the source code. |
signer? |
|
An instance of a Signer. If not provided, a private key must be specified in the |
publisher? |
|
An instance of a Publisher responsible for submitting the DID creation transaction to the Hedera network. |
DIDUpdateOperation Type
This type represents the different operations you can perform to update a DID Document. Each operation modifies the DID Document in a specific way, such as adding a verification method, removing a service, etc.
AddVerificationMethodOperation Type
Adds a new verification method to the DID Document.
Name | Type | Description |
---|---|---|
operation |
|
A constant string representing the operation type. |
id |
|
A unique identifier for the verification method. Must start with |
property |
|
A string representing the verification method or relationship property to add. Possible values are: |
controller? |
|
The DID that controls the verification method. If not provided, the DID of the DID Document is used. |
publicKeyMultibase? |
|
The public key in multibase format to add. Optional when adding verification relationship as an alias to an existing verification method. In that case |
AddServiceOperation Type
Adds a new service endpoint to the DID Document.
Name | Type | Description |
---|---|---|
operation |
|
A constant string representing the operation type. |
id |
|
A unique identifier for the service. Must start with |
type |
|
The type of service to add. |
serviceEndpoint |
|
The service endpoint to add. |
RemoveVerificationMethodOperation Type
Removes an existing verification method from the DID Document.
Name | Type | Description |
---|---|---|
operation |
|
A constant string representing the operation type. |
id |
|
A unique identifier for the verification method or relationship to remove. Must start with |
Return Value
Upon successful execution, the function returns a Promise that resolves to a UpdateDIDResult
object.
Name | Type | Description |
---|---|---|
did |
|
The updated DID string of the Decentralized Identifier. |
didDocument |
|
The updated DID Document associated with the Decentralized Identifier. |
Errors
The following table enumerates the exceptions that may arise during the execution of the updateDID
function.
Exception code | Description |
---|---|
|
Providers must contain client options or client or publisher. |
|
Hashgraph SDK Client must be configured with a network. |
|
Hashgraph SDK Client must be configured with an operator account. |
|
Signer or private key is required to perform the operation. |
|
Verification method ID does not exist. Nothing to remove. |
|
Cannot remove a service using |
|
Service id already exists. |
|
The service endpoint must be a valid URI. |
|
The ID must be a valid property ID. |
|
The fragment ID # is already in use for another verification method. |
|
The DID must be a valid Hedera DID. |
|
The controller must be a valid Hedera DID. |
|
The DID document was not found. |
|
The public key is required for verification methods |
|
Invalid length for the public key. |
|
The signature is invalid. Provided signer does not match the DID signer. |
|
Message awaiter timeout reached. Messages not found. |
|
The signature is invalid. Provided signer does not match the DID signer. |
Function Implementation
The Hashgraph DID SDK provides a updateDID
function within its registrar
package. For further details, refer to the @hashgraph-did-sdk-js/registrar
package documentation.