Core API Reference

This document provides a concise API reference for the core interfaces, utilities, and functions within the Hedera DID SDK for JavaScript.

Interfaces

DIDDocument

Represents a DID Document, which contains information about a DID, such as its public keys and services.

Interface Diagram

did document interface diagram

Properties

Name Type Description

id

string

The DID string of the Decentralized Identifier.

controller

string

The DID that controls the DID document.

verificationMethod

VerificationMethod[]

An array of verification methods associated with the DID.

authentication?

(VerificationMethod | string)[]

An optional array of verification method IDs or verification methods that can be used for authentication.

assertionMethod?

(VerificationMethod | string)[]

An optional array of verification method IDs or verification methods that can be used for assertion.

keyAgreement?

(VerificationMethod | string)[]

An optional array of verification method IDs or verification methods that can be used for key agreement.

capabilityInvocation?

(VerificationMethod | string)[]

An optional array of verification method IDs or verification methods that can be used for capability invocation.

capabilityDelegation?

(VerificationMethod | string)[]

An optional array of verification method IDs or verification methods that can be used for capability delegation.

service?

Service[]

An optional array of services associated with the DID.

Signer

Defines the methods for signing and verifying data using a DID’s private key. It supports only ED25519 signatures.

Interface Diagram

signer interface diagram

Properties

Name Type Description

sign

(message: Uint8Array) ⇒ Promise<Uint8Array> | Uint8Array

Asynchronously signs the provided message using the signer’s private key and returns a Promise that resolves to the signature.

publicKey

() ⇒ Promise<PublicKeyInDer> | PublicKeyInDer

Asynchronously retrieves the public key associated with the signer in DER format.

verify

(message: Uint8Array, signature: Uint8Array) ⇒ Promise<boolean> | boolean

Asynchronously verifies the given signature against the provided message using the signer’s public key, returning a Promise that resolves to true if the signature is valid, false otherwise.

Verifier

Defines the methods for verifying the signatures of DID operations. It supports only ED25519 signatures. Can be used to verify the signatures when having only the public key.

Interface Diagram

verifier interface diagram

Properties

Name Type Description

publicKey

() ⇒ Promise<PublicKeyInDer> | PublicKeyInDer

Asynchronously retrieves the public key associated with the signer in DER format.

verify

(message: Uint8Array, signature: Uint8Array) ⇒ Promise<boolean> | boolean

Asynchronously verifies the given signature against the provided message using the signer’s public key, returning a Promise that resolves to true if the signature is valid, false otherwise.

Publisher

Defines the methods for submitting transactions to the Hedera network.

Interface Diagram

publisher interface diagram

Properties

Name Type Description

network

() ⇒ Network

Returns the name of the Hedera network used by the publisher, eg. "mainnet" or "testnet".

publicKey

() ⇒ PublicKey

Returns the public key of the account used by the publisher.

publish

(transaction: Transaction) ⇒ Promise<TransactionReceipt> | TransactionReceipt

Asynchronously submits the provided transaction to the network, executes it, and returns a Promise that resolves to a result object containing the outcome of the transaction.

DIDMessage

Represents a message used for DID operations, such as creating, updating, or deactivating a DID. It’s an abstract class that can be extended to create specific DID operation messages.

Interface Diagram

did message interface diagram

Properties

Name Type Description

signature?

Uint8Array

The signature of the DID message.

operation?

DIDMessageOperation

The DID operation to be performed, eg. "create", "update", "revoke".

did

string

The DID string of the Decentralized Identifier.

message

object

The message object containing the data to be signed according to the DID operation and Hedera DID specification.

topicId

string

The topic ID where the DID message will be published.

messageBytes

Uint8Array

A byte array representation of the message object. This is used for signing the message.

payload

string

Gets the payload of the DID message that will be published to the Hedera network. it contains the message object and the signature.

Methods

Name Type Description

signWith

signWith(signer: Signer): Promise<void>

Signs the DID message using the provided signer.

setSignature

setSignature(signature: Uint8Array, verifier: Verifier): Promise<void>

Sets the signature of the DID message and verifies it using the provided verifier.

toBytes

toBytes(): string

Converts the DID message to a byte array in a base64-encoded string format.

static fromBytes

static fromBytes(bytes: string): DIDMessage

A static method that creates a DID message from a byte array in a base64-encoded string format.

DIDError

A custom error class for all SDK-related errors. It extends the JavaScript Error class and provides additional properties for error handling.

Interface Diagram

diderror interface diagram

Properties

Name Type Description

isDIDError

boolean

Always true to indicate that the error is a DID-related error.

code

ErrorCodes

The error code that identifies the type of error.

description

string

A human-readable description of the error. Provides additional information about the error.

ErrorCodes

A enumerated type for defining error codes used by the DIDError class.

type ErrorCodes =
  | 'invalidDid'
  | 'invalidDidUrl'
  | 'methodNotSupported'
  | 'representationNotSupported'
  | 'invalidPublicKey'
  | 'invalidPublicKeyLength'
  | 'invalidPublicKeyType'
  | 'unsupportedPublicKeyType'
  | 'internalError'
  | 'notFound'
  | 'invalidSignature'
  | 'invalidMultibase'
  | 'invalidArgument';

Network

A enumerated type for defining Hedera network configurations. It specifies the network of the Hedera DID document.

Interface

type Network = 'mainnet' | 'testnet' | 'previewnet' | 'local-node';

VerificationMethodProperties

A enumerated type for defining verification method properties. It specifies the properties of a verification method, such as authentication, assertionMethod, keyAgreement, capabilityInvocation, and capabilityDelegation.

Interface

type VerificationMethodProperties =
  | 'verificationMethod'
  | 'authentication'
  | 'assertionMethod'
  | 'keyAgreement'
  | 'capabilityInvocation'
  | 'capabilityDelegation';

Utilities

KeysUtility

Provides methods for generating, transforming, and validating cryptographic keys.

Class Diagram

keys utility class diagram

Properties

Name Type Description

toMultibase

(algorithm: MultibaseAlgorithm) ⇒ string

Converts the key to multibase format using the specified algorithm.

toBase58

() ⇒ string

Converts the key to a base58-encoded string.

toBytes

() ⇒ Uint8Array

Converts the key to a byte array.

toPublicKey

() ⇒ PublicKey

Converts the key to a Hedera PublicKey.

fromPublicKey

static (publicKey: PublicKey) ⇒ KeysUtility

Creates a new KeysUtility instance from a Hedera PublicKey.

fromDerString

static (der: string) ⇒ KeysUtility

Creates a new KeysUtility instance from a DER-encoded public key.

fromBytes

static (bytes: Uint8Array) ⇒ KeysUtility

Creates a new KeysUtility instance from a byte array.

fromBase58

static (base58String: string) ⇒ KeysUtility

Creates a new KeysUtility instance from a base58-encoded public key.

fromMultibase

static (multibase: string) ⇒ KeysUtility

Creates a new KeysUtility instance from a multibase-encoded public key.

MultibaseCodec

Provides methods for encoding and decoding data using the multibase encoding format. Supported algorithms: base16, base16upper, base32, base32upper, base58btc, base64, base64url, base64urlpad.

Class Diagram

multibase utility class diagram

Properties

Name Type Description

decode

static (data: string) ⇒ Uint8Array

Decodes a multibase-encoded string to a byte array.

encode

static (data: Uint8Array, algorithm: MultibaseAlgorithm) ⇒ string

Encodes a byte array to a multibase-encoded string using the specified algorithm. Default algorithm is base58btc.

CborCodec

Provides methods for encoding and decoding data using the CBOR encoding format. It allows to encode data to bytes or hex strings and decode bytes or hex strings to data.

Class Diagram

cbor utility class diagram

Properties

Name Type Description

decode

static (data: Uint8Array | string) ⇒ Uint8Array

Decodes a CBOR-encoded byte array or hex string to a byte array.

encode

static (data: Uint8Array | string | object) ⇒ Uint8Array

Encodes a byte array, hex string, or object to a CBOR-encoded byte array.

encodeHex

static (data: Uint8Array | string | object) ⇒ string

Encodes a byte array, hex string, or object to a CBOR-encoded hex string.

Validation

isHederaDID

Checks if a given string is a valid Hedera DID. Returns true if the string is a valid DID, false otherwise.

Function Signature

function isHederaDID(did: string): boolean;

isHederaDIDUrl

Checks if a given string is a valid Hedera DID URL. Returns true if the string is a valid DID URL, false otherwise.

Function Signature

function isHederaDIDUrl(didUrl: string): boolean;

isEd25519PublicKey

Checks if a given byte array or multibase string is a valid ED25519 public key. Returns true if the byte array or multibase string is a valid ED25519 public key, false otherwise. It only check the length of the key.

Function Signature

function isEd25519PublicKey(bytes: Uint8Array): boolean;

function isEd25519PublicKey(multibase: string): boolean;

Component Implementation

The Hashgraph DID SDK provides the core interfaces, utilities, and validation tools within its core package. For further details, refer to the @hashgraph-did-sdk-js/core package documentation.