deactivateDID Function
The deactivateDID
function is a core component of the Hashgraph DID SDK, responsible for deactivating existing DIDs for the Hedera DID method. This action effectively revokes the DID, making it unusable for future operations.
Features
-
DID Deactivation: Deactivates registered DIDs on the Hedera network, revoking their validity.
-
Secure Deactivation: Ensures secure and verifiable deactivation by leveraging the Hedera Consensus Service (HCS).
-
DID Document Update: Updates the DID Document to reflect the deactivated status of the DID.
-
Hedera Network Support: Supports DID deactivation on the Hedera mainnet and testnet.
-
Error Handling: Provides robust error handling for invalid input, network issues, and other potential problems.
-
TypeScript Support: Built with TypeScript to enhance developer experience and type safety.
Deactivating a DID Document
The following examples demonstrate how to deactivate a DID document using the deactivateDID
function in different scenarios.
With Client Options
You can customize the Hedera network and account used for deactivating the DID by providing clientOptions
to the deactivateDID
function.
const clientOptions = {
privateKey: "0x...", // Replace with your Hedera account private key
accountId: "0.0.0....", // Replace with your Hedera account ID
network: "testnet",
};
await deactivateDID({ did }, { clientOptions });
In this example, deactivateDID
takes the DID to be deactivated and an object containing the clientOptions
. This configuration object should include the necessary information to interact with the Hedera network, such as the private key, account ID, and network.
See a full running example in the source code.
With a Hedera Client
You can provide a Hedera Client
instance directly to the deactivateDID
function. This allows for more fine-grained control over the client configuration and network interaction.
const client = Client.forTestnet();
client.setOperator(accountId, privateKey);
await deactivateDID({ did }, { client });
In this example, a pre-configured Hedera Client
instance is passed to the deactivateDID
function.
See a full running example in the source code.
Using Client Managed Secret Mode
In certain instances, keys are managed in a fashion that does not allow direct or indirect access by the SDK. Or you prefer to manage your keys yourself. In such a scenario, Client Managed Secret Mode can be utilized. In this mode, the DID SDK generates a signing request for you, so you can handle the signing process yourself. From it’s design, the process is divided into two steps: generateDeactivateDIDRequest
and submitDeactivateDIDRequest
.
The signing request contains all the necessary information about the algorithm of the signing and data to be signed. The serialized payload of the request is signed by the client and submitted to the SDK. The SDK then processes the request and deactivate the DID Document.
const { state, signingRequest } = await generateDeactivateDIDRequest(
{
did,
},
{
client,
},
);
const signature = await wallet.sign(signingRequest.serializedPayload);
const deactivatedDidDocument = await submitDeactivateDIDRequest(
{
state,
signature,
},
{
client,
},
);
See a full running example in the source code.
You can learn more about the Client Managed Secret Mode in the Key Management Modes Guide.