Lifecycle API Reference

This document provides a concise API reference for the Lifecycle Management component within the Hedera DID SDK for JavaScript.

Classes

LifecycleBuilder

The LifecycleBuilder class provides a fluent interface for defining the steps involved in a DID operation.

Class Diagram

lifecycle builder class diagram

Properties

length
public length: number

Gets the number of steps in the lifecycle.

catchStep
public catchStep?: CatchStep

Gets the catch step in the lifecycle that handles errors. undefined if no catch step is defined.

Methods

callback
callback(label: string, callback: (message: Message, publisher: Publisher) => Promise<void> | void): LifecycleBuilder

Adds a callback step to the lifecycle.

Parameters
  • label: A unique identifier for the callback step.

  • callback: A function that will be executed asynchronously. It receives a Message object and a Publisher object as parameters, which provides access to data and utilities within the lifecycle.

Returns

The LifecycleBuilder instance for method chaining.

signature
signature(label: string): LifecycleBuilder

Adds a signature step to the lifecycle. This step is used to add signature to the message using the provided signature as an option in lifecycle runner.

Parameters
  • label: A unique identifier for the signature step.

Returns

The LifecycleBuilder instance for method chaining.

signWithSigner
signWithSigner(label: string): LifecycleBuilder

Adds a signing step with a Signer class to the lifecycle. This step uses the Signer provided in the lifecycle runner to sign the data.

Parameters
  • label: A unique identifier for the sign with signer step.

Returns

The LifecycleBuilder instance for method chaining.

pause
pause(label: string): LifecycleBuilder

Adds a pause step to the lifecycle. This allows for manual intervention or waiting for external events before continuing the execution.

Parameters
  • label: A unique identifier for the pause step.

Returns

The LifecycleBuilder instance for method chaining.

catch
catch(label: string, callback: (error: unknown) => void | Promise<void>): LifecycleBuilder

Adds a catch step to the lifecycle. This step is used to handle errors that occur during the execution of previous steps.

Parameters
  • label: A unique identifier for the catch step.

  • callback: A function that will be executed if an error occurs. It receives the error object as a parameter.

Returns

The LifecycleBuilder instance for method chaining.

getByIndex
getByIndex(stepIndex: number): Steps<Message>

Gets the step at the specified index in the lifecycle.

Parameters
  • stepIndex: A number representing the index of the step to retrieve.

Returns

A Steps<Message> object representing the step at the specified index.

Errors

The following exceptions may arise during the execution of the getByIndex function:

Exception code Description

internalError

Step index out of bounds.

getByLabel
getByLabel(stepLabel: string): Steps<Message>

Gets the step with the specified label in the lifecycle.

Parameters
  • stepLabel: A string representing the label of the step to retrieve.

Returns

A Steps<Message> object representing the step with the specified label.

Errors

The following exceptions may arise during the execution of the getByLabel function:

Exception code Description

internalError

Step with label # does not exist.

getIndexByLabel
getIndexByLabel(stepLabel: string): number

Gets the index of the step with the specified label in the lifecycle.

Parameters
  • stepLabel: A string representing the label of the step to retrieve.

Returns

A number representing the index of the step with the specified label.

Errors

The following exceptions may arise during the execution of the getByLabel function:

Exception code Description

internalError

Step with label # does not exist.

LifecycleRunner

The LifecycleRunner class is responsible for executing a Lifecycle.

Class Diagram

lifecycle runner class diagram

Methods

constructor
constructor(builder: LifecycleBuilder<Message>): LifecycleRunner

Initializes a new LifecycleRunner instance.

Parameters
  • builder: A LifecycleBuilder object representing the lifecycle steps.

Returns

A new LifecycleRunner instance.

process
process(
  message: Message,
  options: LifecycleRunnerOptions,
): Promise<RunnerState<Message>>

Starts the execution of the lifecycle.

Parameters
  • message: The initial message to be processed by the lifecycle.

  • options: A LifecycleRunnerOptions object providing additional options for the lifecycle runner, like the Publisher and Signer instances.

Returns

A Promise that resolves to a LifecycleState object, which contains information about the current state of the lifecycle and processed message.

Errors

The following exceptions may arise during the execution of the process function:

Exception code Description

invalidArgument

Signature and verifier are required for the signature step.

invalidArgument

Signer is missing, but required.

resume
resume(
  state: RunnerState<Message>,
  options: LifecycleRunnerOptions,
): Promise<RunnerState<Message>>

Resumes the execution of a paused lifecycle.

Parameters
  • state: The RunnerState object representing the paused state of the lifecycle.

  • context: A LifecycleRunnerOptions object providing additional options for the lifecycle runner, like the Publisher and Signer instances.

Returns

A Promise that resolves to a RunnerState object, which contains information about the current state of the lifecycle.

Errors

The following exceptions may arise during the execution of the resume function:

Exception code Description

invalidArgument

Signature and verifier are required for the signature step.

invalidArgument

Signer is missing, but required.

onComplete
onComplete(label: string, callback: (message: Message,) => void | Promise<void>): void

Registers a callback to be executed when the lifecycle step with the specified label is completed.

Parameters
  • label: The label of the lifecycle step.

  • callback: A function to be executed when the step is completed.

Component Implementation

The Hashgraph DID SDK provides the Lifecycle Management classes and interfaces within its lifecycle package. For further details, refer to the @hashgraph-did-sdk-js/lifecycle package documentation.