# DIDs

`Did`s are a core component of the Cloud Agent, they are the identifiers that the cloud agent uses when engaging in DI operations (e.g. issuing VCs).

## Create a DID

The Cloud Agent service supports multiple DID types (DID methods) to be created. All DIDs are created with the `createDid` mutation, with different inputs depending on the DID method. A private human readable and searchable `alias` can be assigned to DIDs for record-keeping purposes.

### Cheqd DID

`did:cheqd` DIDs can be created by the cloud agent and written permanently to the cheqd ledger as a production-ready DID. The `network` parameter determines whether the DID is created on testnet or mainnet.

```graphql
mutation MyMutation {
  createDid(
    input: {
      alias: "MyCheqdDID"
      createCheqdDidOptions: {
        network: TESTNET
      }
    }
  ) {
    did
    alias
    methodData {
      ... on CheqdDidMethodData {
        network
      }
    }
    createdTimestamp
    primary
  }
}
```

### Key DID

Alternatively, `did:key` DIDs are a basic no-cost DID that the cloud agent can create, ideal for development. The `keyType` parameter determines which cryptographic key type is used for the DID.

```graphql
mutation MyMutation {
  createDid(
    input: {
      alias: "MyKeyDID"
      createKeyDidOptions: {
        keyType: ED25519
      }
    }
  ) {
    did
    alias
    methodData {
      ... on KeyDidMethodData {
        keyType
      }
    }
    createdTimestamp
    primary
  }
}
```

## Set a primary DID

A Cloud Agent DID can be set the 'primary' DID for the agent, unsetting any existing primary DID. Setting a primary DID is purely for referential and record-keeping purposes when interacting with the Cloud Agent.

```graphql
mutation MyMutation {
  setPrimaryDid(
    did: "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
  ) {
    did
    alias
    primary
    modifiedTimestamp
  }
}
```

## Update a DID

A DID's metadata, including its alias and archived status can be updated.

```graphql
mutation MyMutation {
  updateDid(
    did: "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
    input: {
      updateAlias: "UpdatedAlias"
      updatedArchived: false
    }
  ) {
    did
    alias
    archived
    modifiedTimestamp
  }
}
```

## View DIDs

DIDs created by the cloud agent can be listed, using pagination and filtering options. This query returns a `nextToken` which can be passed into the same query in order to fetch subsequent pages.

```graphql
query MyQuery {
  dids(
    page: {
      nextToken: null
    }
    filter: {
      methods: [KEY, CHEQD]
      archived: false
    }
  ) {
    items {
      did
      alias
      methodData {
        ... on KeyDidMethodData {
          keyType
        }
        ... on CheqdDidMethodData {
          network
        }
      }
      primary
      createdTimestamp
    }
    nextToken
  }
}
```

Alternatively, a single DID can be viewed, referenced by its unique identifier.

```graphql
query MyQuery {
  did(
    did: "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
  ) {
    did
    alias
    methodData {
      ... on KeyDidMethodData {
        keyType
      }
    }
    primary
    archived
    createdTimestamp
  }
}
```

The current primary DID for the agent can be viewed with a standalone query.

```graphql
query MyQuery {
  primaryDid {
    did
    alias
    methodData {
      ... on KeyDidMethodData {
        keyType
      }
      ... on CheqdDidMethodData {
        network
      }
    }
    primary
    createdTimestamp
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sudoplatform.com/guides/decentralized-identity/cloud-agent/cloud-agent-admin-api/dids.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
