@arcblock/did


This package provides a JavaScript library for working with ArcBlock's Decentralized Identity (DID) protocol. It allows you to create, manage, and validate DIDs, which are fundamental for building applications on the OCAP platform. This section covers the essential functionalities of the library.

For a deeper understanding of the underlying principles, please see our Core Concepts. For a detailed breakdown of all available functions, refer to the API Reference.

Installation#

To get started, install the necessary packages using npm or your preferred package manager.

Installation

npm install @ocap/mcrypto @arcblock/did

Quick Start#

You can easily generate a new DID from a secret key. The library handles the cryptographic operations to derive the public key and construct the corresponding DID address based on the specified role and cryptographic types.

Generate a DID from a Secret Key

const Mcrypto = require('@ocap/mcrypto');
const { fromSecretKey } = require('@arcblock/did');

// Destructure required types from Mcrypto
const { types } = Mcrypto;

// 1. Generate a new Ed25519 key pair
const keyPair = Mcrypto.Signer.Ed25519.genKeyPair();

// 2. Generate a DID from the secret key
// We specify the role, public key type, and hash algorithm
const didAddress = fromSecretKey(keyPair.secretKey, {
  role: types.RoleType.ROLE_APPLICATION,
  pk: types.KeyType.ED25519,
  hash: types.HashType.SHA3,
});

// 3. The full DID string includes the 'abt:did:' prefix
console.log(`Generated DID: abt:did:${didAddress}`);

This example demonstrates the basic workflow for creating an application DID. For more advanced use cases, such as creating DIDs from public keys or validating DID ownership, please refer to the detailed guides in the following sections.

Next Steps#

Dive deeper into the specifics of ArcBlock DIDs by exploring the following sections.