Skip to main content
Version: v0.4.x

Cheqd Did Module

In this tutorial we will see how to use the cheqd modules in detail

info

This section assumes that

  1. You have set-up your develoment environment.
  2. You have setup the cheqd module setup cheqd

DID Module

The cheqd DID module facilitates the Create, Read, Update, and Delete (CRUD) operations for did:cheqd identifiers. To learn more about "did:cheqd," please refer to the specification

Create DID

The DID can be created in two different ways

Parameters

  1. method*: cheqd
  2. secret
  3. options*
  4. didDocument
Option 1

Provide a DID Document payload according to the w3c did core specification in the request body. This is possible when the keys corresponding to the verification methods provided in the DID Document are already created in the wallet


// create a key pair
const key = await agent.wallet.createKey({
keyType: KeyType.Ed25519,
})

// encode public key according to the verification method
const ed25519PublicKeyBase58 = key.publicKeyBase58

// Create a DID
await agent.dids.create<CheqdDidCreateOptions>({
method: 'cheqd',
secret: {},
options: {
network: 'testnet',
},
didDocument: new DidDocument({
id: 'did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d',
controller: ['did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d'],
verificationMethod: [
{
id: 'did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d#key-1',
type: 'Ed25519VerificationKey2018',
controller: 'did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d',
publicKeyBase58: ed25519PublicKeyBase58,
},
],
authentication: ['did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d#key-1'],
}),
})
Option 2

If a DID Document is not passed to the registrar, it requires the secret parameter with a verificationMethod to construct the DID Document.

await agent.dids.create({
method: 'cheqd',
// the secret contains a the verification method type and id
secret: {
verificationMethod: {
id: 'key-1',
type: 'Ed25519VerificationKey2020',
},
},
// an optional methodSpecificIdAlgo parameter
options: {
network: 'testnet',
methodSpecificIdAlgo: 'uuid',
},
})

Update DID

To update a DID Document, fetch the body of the DID Document you want to change from the DID Resolver, make the relevant updates and pass it as the parameter

Parameters

  1. did*
  2. didDocument*: The updated DID Document
  3. options
  4. secret
await agent.dids.update({
did: 'did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411',
// Updates DID Document with an additional verification method if provided
secret: {
verificationMethod: {
id: 'key-2',
type: 'JsonWebKey2020',
},
},
didDocument: {
id: 'did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411',
controller: ['did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411'],
verificationMethod: [
{
id: 'did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411#key-1',
type: 'Ed25519VerificationKey2020',
controller: 'did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411',
publicKeyMultibase: 'z6MknkzLUEP5cxqqsaysNMWoh8NJRb3YsowTCj2D6yhwyEdj',
},
],
authentication: ['did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411#key-1'],
// updates did document with a service block
service: [
new DidDocumentService({
id: 'did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411#rand',
type: 'rand',
serviceEndpoint: 'https://rand.in',
}),
],
},
})

Deactivate DID

A DID can be deactivated, it can still be resolved

Parameters

  1. did*
  2. options
await agent.dids.deactivate({
did: 'did:cheqd:testnet:b84817b8-43ee-4483-98c5-f03760816411',
// an optional versionId parameter
options: {
versionId: '3.0',
},
})

Types


secret.verificationMethod

Type: verificationMethod

verificationMethod.id*

Type: string

verificationMethod.type*

Type: string

Default: Ed25519VerificationKey2020

Members:

  1. Ed25519VerificationKey2020
  2. Ed25519VerificationKey2018
  3. JsonWebKey2020
verificationMethod.privateKey

Type: string


options.methodSpecificIdAlgo

Specifies what type of method specific identifier is needed for your DID

Type: string

Default: uuid

Members:

  1. uuid
  2. base58btc

options.network*

Specifies the cheqd network name to be published

Type: string

Default: testnet

Members:

  1. testnet
  2. mainnet

options.versionId

Specifies the version of the DID Document to be published

Type: string