The did module is used to manage decentralized identifiers (DIDs) via the TrustStack platform.

Installation

With @truststack/sdk installed and configured, or alternatively, just the @truststack/did package.

npm install @truststack/sdk
# or
npm install @truststack/did

Issuing a DID

DIDs against issued against and scoped to an organization. A single organization can have multiple DIDs issued so long as a unique name is provided.

import {DidClient} from "@truststack/did";

const client = new DidClient();

const did = await client.createDid(
  {
    name: "acme-farms",
  },
  {
    organizationId: "ACME-FARMS-ID",
  }
);

console.log(did);

This generates a did:web DID scoped to the organization and name provided. The response returned is below.

Response
{
  "id": "94A78270-56AB-4EFA-8EE0-B6A3D3D009B2",
  "did": "did:web:trustdid.dev:o:<ORG_ID>:acme-farms",
  "alias": "did:web:trustdid.dev:o:<ORG_ID>:acme-farms",
  "name": "acme-farms",
  "createdAt": "2024-03-20T10:30:00Z",
  "updatedAt": "2024-03-20T10:30:00Z"
}

DID Structure

The DID is constructed as follows:

did:web:trustdid.dev:o:<ORG_ID>:<NAME>

Where <ORG_ID> is the organizationId and <NAME> is the name provided to the createDid method.

Deleting a DID

DIDs can be deleted by calling the deleteDid method.

import {DidClient} from "@truststack/did";

const client = new DidClient();

// Unique ID of the DID to delete
await client.deleteDid("94A78270-56AB-4EFA-8EE0-B6A3D3D009B2");