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.
Properties
| Name | Type | Description |
|---|---|---|
id |
|
The DID string of the Decentralized Identifier. |
controller |
|
The DID that controls the DID document. |
verificationMethod |
|
An array of verification methods associated with the DID. |
authentication? |
|
An optional array of verification method IDs or verification methods that can be used for authentication. |
assertionMethod? |
|
An optional array of verification method IDs or verification methods that can be used for assertion. |
keyAgreement? |
|
An optional array of verification method IDs or verification methods that can be used for key agreement. |
capabilityInvocation? |
|
An optional array of verification method IDs or verification methods that can be used for capability invocation. |
capabilityDelegation? |
|
An optional array of verification method IDs or verification methods that can be used for capability delegation. |
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.
Properties
| Name | Type | Description |
|---|---|---|
sign |
|
Asynchronously signs the provided message using the signer’s private key and returns a |
signTransaction |
|
Asynchronously signs the provided Hiero SDK Transaction using the signer’s private key and returns a |
publicKey |
|
Asynchronously retrieves the public key associated with the signer in DER format. |
publicKeyInstance |
|
Asynchronously retrieves the Hiero SDK PublicKey instance associated with the signer. |
verify |
|
Asynchronously verifies the given signature against the provided message using the signer’s public key, returning a |
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.
Properties
| Name | Type | Description |
|---|---|---|
publicKey |
|
Asynchronously retrieves the public key associated with the signer in DER format. |
verify |
|
Asynchronously verifies the given signature against the provided message using the signer’s public key, returning a |
Publisher
Defines the methods for submitting transactions to the Hedera network.
Properties
| Name | Type | Description |
|---|---|---|
network |
|
Returns the name of the Hedera network used by the publisher, eg. "mainnet" or "testnet". |
publicKey |
|
Returns the public key of the account used by the publisher. |
publish |
|
Asynchronously submits the provided transaction to the network, executes it, and returns a |
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.
Properties
| Name | Type | Description |
|---|---|---|
signature? |
|
The signature of the DID message. |
operation? |
|
The DID operation to be performed, eg. "create", "update", "revoke". |
did |
|
The DID string of the Decentralized Identifier. |
message |
|
The message object containing the data to be signed according to the DID operation and Hedera DID specification. |
topicId |
|
The topic ID where the DID message will be published. |
messageBytes |
|
A byte array representation of the message object. This is used for signing the message. |
payload |
|
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 |
|
Signs the DID message using the provided signer. |
setSignature |
|
Sets the signature of the DID message and verifies it using the provided verifier. |
toBytes |
|
Converts the DID message to a byte array in a base64-encoded string format. |
static fromBytes |
|
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.
Properties
| Name | Type | Description |
|---|---|---|
isDIDError |
|
Always |
code |
|
The error code that identifies the type of error. |
description |
|
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.
Utilities
KeysUtility
Provides methods for generating, transforming, and validating cryptographic keys.
Properties
| Name | Type | Description |
|---|---|---|
toMultibase |
|
Converts the key to multibase format using the specified algorithm. |
toBase58 |
|
Converts the key to a base58-encoded string. |
toBytes |
|
Converts the key to a byte array. |
toPublicKey |
|
Converts the key to a Hedera |
fromPublicKey |
|
Creates a new |
fromDerString |
|
Creates a new |
fromBytes |
|
Creates a new |
fromBase58 |
|
Creates a new |
fromMultibase |
|
Creates a new |
MultibaseCodec
Provides methods for encoding and decoding data using the multibase encoding format.
Supported algorithms: base16, base16upper, base32, base32upper, base58btc, base64, base64url, base64urlpad.
Properties
| Name | Type | Description |
|---|---|---|
decode |
|
Decodes a multibase-encoded string to a byte array. |
encode |
|
Encodes a byte array to a multibase-encoded string using the specified algorithm. Default algorithm is |
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.
Properties
| Name | Type | Description |
|---|---|---|
decode |
|
Decodes a CBOR-encoded byte array or hex string to a byte array. |
encode |
|
Encodes a byte array, hex string, or object to a CBOR-encoded byte array. |
encodeHex |
|
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.
isHederaDIDUrl
Checks if a given string is a valid Hedera DID URL. Returns true if the string is a valid DID URL, false otherwise.
Component Implementation
The Hiero DID SDK provides the core interfaces, utilities, and validation tools within its core package. For further details, refer to the @hiero-did-sdk-js/core package documentation.