Types


This section provides a detailed reference for the core TypeScript types and interfaces used throughout the DID Space component library. Understanding these data structures is essential for correctly typing component props and managing state in your application.


DIDSpaceStatus#

An enum representing the various connection states of a DID Space. This is used by components like DIDSpaceConnection to display the current status visually.

DIDSpaceStatus Enum

export enum DIDSpaceStatus {
  LOADING = 'loading',
  CONNECTED = 'connected',
  DISCONNECTED = 'disconnected',
  /** Not available, related to subscription status, e.g., expired, overdue, insufficient usage, etc. */
  UNAVAILABLE = 'unavailable',
}

Member

Value

Description

LOADING

'loading'

The component is currently attempting to connect or fetch the space status.

CONNECTED

'connected'

A successful and active connection to the DID Space is established.

DISCONNECTED

'disconnected'

The component is not connected to the DID Space.

UNAVAILABLE

'unavailable'

The DID Space cannot be accessed due to an issue like an expired subscription or insufficient usage.


DIDSpaceGateway#

This interface defines the structure for an object containing all the necessary information about a DID Space gateway. It is a key prop for components like DIDSpaceConnection to render space details.

DIDSpaceGateway Interface

export interface DIDSpaceGateway {
  did: string;
  name: string;
  url: string;
  endpoint: string;
  ownerDid: string;
  protected?: boolean;
  loading?: boolean;
}
did
string
required
The unique Decentralized Identifier (DID) of the space.
name
string
required
The display name of the space.
url
string
required
The base URL for the space's web interface (e.g., https://spaces.arcblock.io/app).
endpoint
string
required
The API endpoint URL for interacting with the space.
ownerDid
string
required
The DID of the space's owner.
protected
boolean
Indicates if the space requires authentication for access.
loading
boolean
A flag to indicate if the space data is currently being fetched.


AuthorizeConnect#

This interface defines the configuration options for the authentication modal that appears when a user initiates a connection.

AuthorizeConnect Interface

export interface AuthorizeConnect {
  open: boolean;
  action: string;
  checkFn: Function;
  messages: {
    title: string;
    scan: string;
    confirm: string;
    success: React.ReactNode;
  };
  prefix?: string;
  baseUrl?: string;
  webWalletUrl?: string;
  maxIdleTime?: number;
  checkTimeout?: number;
  extraParams?: Record<string, any>;
}
open
boolean
required
Controls the visibility of the connection modal.
action
string
required
The action type for the authentication request (e.g., 'connect').
checkFn
Function
required
A function used to poll or verify the authentication status.
messages
object
required
Custom text and content to display in the authentication modal.
4 subfields
prefix
string
URL prefix for the DID Connect endpoint.
baseUrl
string
The base URL for the DID Connect service.
webWalletUrl
string
The URL of the web wallet to use for the connection.
maxIdleTime
number
Maximum idle time in milliseconds before the session times out.
checkTimeout
number
The timeout in milliseconds for the status check function.
extraParams
Record<string, any>
Additional parameters to include in the authentication request.


Authentication Options#

These interfaces define the options available for customizing the authentication process when connecting to a DID Space.

BaseAuthOptions#

Provides a set of common options for any authentication request, used to configure callbacks and session parameters.

BaseAuthOptions Interface

export interface BaseAuthOptions {
  action?: string;
  checkFn?: Function;
  extraParams?: Record<string, string>;
  checkTimeout?: number;
  onSuccess?: (response: Record<string, string>, decrypt: Function) => Promise<void>;
  onClose?: () => void;
}
action
string
The specific action for the authentication request (e.g., 'login').
checkFn
Function
A custom function to poll or verify the authentication status.
extraParams
Record<string, string>
Extra parameters to include in the authentication request.
checkTimeout
number
The timeout in milliseconds for the status check function.
onSuccess
Function
A callback function that executes upon successful authentication.
onClose
Function
A callback function that executes when the authentication dialog is closed.

GatewayAuthOptions#

Extends BaseAuthOptions with additional properties required for connecting specifically to a DID Space gateway.

GatewayAuthOptions Interface

export interface GatewayAuthOptions extends BaseAuthOptions {
  spaceDid?: string;
  spaceGatewayUrl?: string;
}
spaceDid
string
The DID of the target DID Space.
spaceGatewayUrl
string
The URL of the gateway for the DID Space.

This interface inherits all properties from BaseAuthOptions.


Type Aliases#

For convenience and backward compatibility, the following type aliases are provided. It is recommended to use the primary types in new code.

Compatibility Aliases

// For compatibility
export type SpaceGateway = DIDSpaceGateway;
export const SpaceStatus = DIDSpaceStatus;
  • SpaceGateway is an alias for DIDSpaceGateway.
  • SpaceStatus is an alias for the DIDSpaceStatus enum.


Next Steps#

Now that you are familiar with the core data structures, you can explore how they are used as props in the main components: