📖
zCloak Doc
  • About zCloak
    • Introduction
    • Tech stack overview
    • Protocol
      • DID Specification
      • VC Specification
    • Glossary
  • Developer Hub
    • Guides
      • did
      • vc operation
        • claim-attest
          • claim
          • attest
          • multi attest
        • issue
    • API Reference
      • DID
      • VC
      • VP
      • message
      • zkp
      • login/providers
    • Developer Tool
      • CLI
  • Resources
    • Ongoing Developer Event
    • Developer Education
    • Media Pack
    • FAQs
Powered by GitBook
On this page
  1. Developer Hub
  2. Guides

did

PreviousGuidesNextvc operation

Last updated 1 year ago

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:

Tutorial

  1. Initialize @noble cryptographic library and wasm;

await initCrypto();
  1. Generate random mnemonics;

const mnemonic = mnemonicGenerate(12);
  1. Generate DID through mnemonics;

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.

  1. Upload DID Document to VDR;

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.

zkid-sdk-example /src/did/createDID.ts