Create a DID

Create a did:cheqd DID using the Credo Agent.

This tutorial shows you how to create a cheqd DID using your configured Credo Agent, and how to publish the associated DID Document to the cheqd ledger.

โš ๏ธ Prerequisites

Before you begin:

  • โœ… Ensure your Credo agent is correctly configured with the @credo-ts/cheqd module

  • โœ… Youโ€™ve set up a cosmosPayerSeed for publishing to the cheqd network

  • โœ… You're connected to the correct network (mainnet or testnet)

Method Overview

Credo supports two approaches to creating a DID:

Option 1 โ€“ Manually construct a full DID Document

Use when you want full control over the DID structure and already have key(s) in your wallet.

Option 2 โ€“ Auto-generate the DID Document

Use when you want Credo to create the DID Document from a key you specify in secret.

Create DID

Parametersโ€‹

  1. method*: cheqd

  2. secret

  3. options*

  4. didDocument

Option 1: Create a DID from a full DID Document

  1. First, generate a key pair:

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

const ed25519PublicKeyBase58 = key.publicKeyBase58
  1. Use that key to construct and register the DID Document:

import { DidDocument } from '@credo-ts/core'

await agent.dids.create<CheqdDidCreateOptions>({
  method: 'cheqd',
  secret: {}, // No secret needed if key is already in wallet
  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',
    ],
  }),
})

๐Ÿ“ Make sure the publicKeyBase58 matches the key in your wallet. The DID will be written to the testnet unless you specify "mainnet" in options.network.

Option 2โ€‹

If you donโ€™t want to manually build a DID Document, you can let Credo handle it based on your input key type and ID.

await agent.dids.create({
  method: 'cheqd',
  secret: {
    verificationMethod: {
      id: 'key-1', // Logical key name
      type: 'Ed25519VerificationKey2020', // Or another supported type
    },
  },
  options: {
    network: 'testnet',
    methodSpecificIdAlgo: 'uuid', // Optional: 'uuid' (default) or 'base58'
  },
})

๐Ÿ” Credo will generate the DID Document using the key referenced in secret and publish it to the network.

Whatโ€™s Next?

Now that your DID is live on the cheqd network, try:

Create DID-Linked Resource

Associate DID-Linked Resources to your DID using Credo.

Issue Verifiable Credentials

Issue Credentials using your cheqd DID using Credo.

Last updated

Was this helpful?