# did

In this tutorial, you will learn how to generate DIDs by generating randomized mnemonics and uploading the DID documents to the VDR via the interface.

> Complete code example: [zkid-sdk-example /src/did/createDID.ts](https://github.com/zCloak-Network/zkid-sdk-example/blob/sdk-v2/src/did/createDID.ts)

## Tutorial

1. Initialize @noble cryptographic library and wasm;

```typescript
await initCrypto();
```

2. Generate random mnemonics;

```typescript
const mnemonic = mnemonicGenerate(12);
```

3. Generate DID through mnemonics;

```typescript
const keyring = new Keyring();
const did = keys.fromMnemonic(keyring, mnemonic, "ecdsa");
```

In the process of generating DIDs from mnemonic, the controller key and the key pairs of two different verification methods need to be managed by keyring structure.

4. Upload DID Document to VDR;

```typescript
const doc = await did.getPublish();
await registerDidDoc(doc);

// src/utils/didHelpers.ts
export async function registerDidDoc(
  didDoc: DidDocument,
  url = process.env.BASE_URL
) {
  const res = await axios.post(`${url}/did`, { didDocument: didDoc });

  if (res.data.code === 200) {
    console.log(`Success: DID Document Registerd (${didDoc.controller})`);
  } else {
    console.log(`ERROR: ${res.data.message}`);
  }
}
```

Uploading a DID document to the VDR requires two steps. First of all, you need to use your own controller key to sign the DID document, and the signature-related information will be appended to the back of the DID document structure, and then initiate a request to the RESTful API interface to send the structure to the server for storage and processing, which will be deposited into the database with Arweave.

Well, through the above steps, you will have mastered how to generate a DID and store it into VDR.


---

# 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.zcloak.network/developer-hub/guides/did.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.
