DEV Community

Cover image for Decentralized Identity Simplified: How to Resolve DIDs Effectively
Chris Siku
Chris Siku

Posted on

Decentralized Identity Simplified: How to Resolve DIDs Effectively

Jane and Bob are set to embrace the anonymous web, but they need to effectively manage their identities in this new digital landscape. This article delves into how Web5 empowers users to manage their digital identities using Decentralized Identifiers (DIDs). We will focus on the technical aspects of DIDs, particularly the resolution process, which allows users to retrieve and interact with their identity documents securely.

Understanding DIDs

Decentralized Identifiers (DIDs) serve as unique identifiers that enable individuals and entities to manage their digital identities independently of central authorities. They facilitate secure and private control over online identities, essential for maintaining privacy in decentralized applications.

Key Features of DIDs

  1. Decentralization: DIDs are stored on distributed networks, ensuring user control over their identities.
  2. Self-Sovereignty: Users maintain independent control over their DIDs, deciding who can access their information.
  3. Verifiability: DIDs link to verifiable credentials, allowing users to prove their identity without unnecessary data disclosures.
  4. Interoperability: DIDs are compatible across diverse platforms, facilitating seamless user interactions.
  5. DID Documents: Each DID corresponds to a DID Document containing public keys, service endpoints, and other metadata necessary for identity verification.

A typical DID appears as a unique resource identifier, such as did:example:123456, and is crucial for identity verification, authentication, and access control in decentralized web applications (DWAs).

Creating DIDs

Before Jane and Bob can explore the decentralized web, they need to create their DIDs. Different DID methods are available, each suited for specific purposes. In Web5, the following methods are currently supported:

  • did:dht: This method utilizes BitTorrent's Mainline Distributed Hash Table (DHT) for managing DIDs and storing DID Documents. It supports essential operations like creating, reading, updating, and deactivating DIDs.
  • did:jwk: This method encodes a JSON Web Key (JWK) in base64url format, providing a straightforward way to create a DID.

Implementation in JavaScript

To demonstrate how to create and resolve DIDs in Web5, we will set up a simple JavaScript project. Ensure you have Node.js and npm installed on your machine.

Set Up Your Project Workspace

Initialize your project with the following commands:



mkdir resolveDid
cd resolveDid
touch index.js
npm init -y


Enter fullscreen mode Exit fullscreen mode

Install the DID Dependencies

Install the required Web5 DID libraries:



npm install @web5/dids@1.1.5


Enter fullscreen mode Exit fullscreen mode

Import DID Methods

Open your index.js file and import the necessary DID methods:



// index.js

import { DidDht } from '@web5/dids'; // for did:dht
import { DidJwk } from '@web5/dids'; // for did:jwk


Enter fullscreen mode Exit fullscreen mode

Create DIDs

You can now create DIDs for Jane and Bob as follows:



// index.js

const janeDid = await DidDht.create({ publish: true });
const bobDid = await DidJwk.create({ publish: true });

// Log the created DIDs
console.log("Jane's DID: ", janeDid);
console.log("Bob's DID: ", bobDid);


Enter fullscreen mode Exit fullscreen mode

Expected Output

When you run the code, you should see output similar to the following:



Jane's DID:  BearerDid {
  uri: 'did:dht:x93tdiotgud98izm9y81hxd93m61yopyijzkqbhtqzshgsbucajy',
  document: { ... },
  metadata: { published: true, versionId: '1728222149' },
  keyManager: LocalKeyManager { ... }
}

Bob's DID:  BearerDid {
  uri: 'did:jwk:eyJjcnYiOiJFZDI1NTE5Iiwia3R5IjoiT0tQIiwieCI6IjB5akd0...'
  document: { ... },
  metadata: {},
  keyManager: LocalKeyManager { ... }
}


Enter fullscreen mode Exit fullscreen mode

Resolving DIDs

Resolving a DID involves retrieving the DID Document associated with a Decentralized Identifier. This document contains critical information such as public keys, authentication methods, and service endpoints.

To resolve the DIDs for Jane and Bob, use the following code:

Resolve Jane's DID



// index.js

const resolvedJaneDid = await DidDht.resolve(janeDid.uri);
const janeDidDocument = resolvedJaneDid.didDocument;
console.log("Jane's DID Document: ", janeDidDocument);


Enter fullscreen mode Exit fullscreen mode

Resolve Bob's DID



// index.js

const resolvedBobDid = await DidJwk.resolve(bobDid.uri);
const bobDidDocument = resolvedBobDid.didDocument;
console.log("Bob's DID Document: ", bobDidDocument);


Enter fullscreen mode Exit fullscreen mode

With the creation and resolution of DIDs, Jane and Bob can securely manage their identities in the decentralized web. This capability not only enhances their privacy but also empowers them with control over their personal data, aligning with the principles of self-sovereignty and decentralization in Web5.

Top comments (0)