本节为整个 DID Space 组件库中使用的核心 TypeScript 类型和接口提供了详细的参考。理解这些数据结构对于在您的应用程序中正确设置组件属性类型和管理状态至关重要。
DIDSpaceStatus
一个表示 DID Space 各种连接状态的枚举。DIDSpaceConnection 等组件使用此枚举来直观地显示当前状态。
DIDSpaceStatus Enum
export enum DIDSpaceStatus {
LOADING = 'loading',
CONNECTED = 'connected',
DISCONNECTED = 'disconnected',
/** 不可用,与订阅状态相关,例如过期、欠费、用量不足等。 */
UNAVAILABLE = 'unavailable',
}| 成员 | 值 | 描述 |
|---|---|---|
LOADING | 'loading' | 组件当前正在尝试连接或获取空间状态。 |
CONNECTED | 'connected' | 已成功建立到 DID Space 的活动连接。 |
DISCONNECTED | 'disconnected' | 组件未连接到 DID Space。 |
UNAVAILABLE | 'unavailable' | 由于订阅过期或用量不足等问题,无法访问 DID Space。 |
DIDSpaceGateway
该接口定义了一个对象的结构,该对象包含有关 DID Space 网关的所有必要信息。它是 DIDSpaceConnection 等组件渲染空间详细信息的关键属性。
DIDSpaceGateway Interface
export interface DIDSpaceGateway {
did: string;
name: string;
url: string;
endpoint: string;
ownerDid: string;
protected?: boolean;
loading?: boolean;
}- did
string(required) — 空间的唯一去中心化标识符 (DID)。 - name
string(required) — 空间的显示名称。 - url
string(required) — 空间 Web 界面的基础 URL(例如,https://spaces.arcblock.io/app)。 - endpoint
string(required) — 用于与空间交互的 API 端点 URL。 - ownerDid
string(required) — 空间所有者的 DID。 - protected
boolean— 指示空间是否需要身份验证才能访问。 - loading
boolean— 一个标志,用于指示当前是否正在获取空间数据。
AuthorizeConnect
该接口定义了用户发起连接时出现的身份验证模态框的配置选项。
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) — 控制连接模态框的可见性。 - action
string(required) — 身份验证请求的操作类型(例如,'connect')。 - checkFn
Function(required) — 一个用于轮询或验证身份验证状态的函数。 - messages
object(required) — 在身份验证模态框中显示的自定义文本和内容。- title
string(required) — 模态框的标题。 - scan
string(required) — 扫描步骤的说明。 - confirm
string(required) — 确认步骤的说明。 - success
React.ReactNode(required) — 连接成功后显示的内容。
- title
- prefix
string— DID Connect 端点的 URL 前缀。 - baseUrl
string— DID Connect 服务的基础 URL。 - webWalletUrl
string— 用于连接的 Web 钱包的 URL。 - maxIdleTime
number— 会话超时前的最大空闲时间(以毫秒为单位)。 - checkTimeout
number— 状态检查函数的超时时间(以毫秒为单位)。 - extraParams
Record<string, any>— 要在身份验证请求中包含的附加参数。
身份验证选项
这些接口定义了在连接到 DID Space 时可用于自定义身份验证过程的选项。
BaseAuthOptions
为任何身份验证请求提供一组通用选项,用于配置回调和会话参数。
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— 身份验证请求的具体操作(例如,'login')。 - checkFn
Function— 一个用于轮询或验证身份验证状态的自定义函数。 - extraParams
Record<string, string>— 要在身份验证请求中包含的额外参数。 - checkTimeout
number— 状态检查函数的超时时间(以毫秒为单位)。 - onSuccess
Function— 在身份验证成功时执行的回调函数。 - onClose
Function— 在身份验证对话框关闭时执行的回调函数。
GatewayAuthOptions
扩展了 BaseAuthOptions,增加了专门用于连接到 DID Space 网关所需的附加属性。
GatewayAuthOptions Interface
export interface GatewayAuthOptions extends BaseAuthOptions {
spaceDid?: string;
spaceGatewayUrl?: string;
}- spaceDid
string— 目标 DID Space 的 DID。 - spaceGatewayUrl
string— DID Space 网关的 URL。
该接口继承了 BaseAuthOptions 的所有属性。
类型别名
为方便和向后兼容,提供了以下类型别名。建议在新代码中使用主类型。
Compatibility Aliases
// For compatibility
export type SpaceGateway = DIDSpaceGateway;
export const SpaceStatus = DIDSpaceStatus;SpaceGateway是DIDSpaceGateway的别名。SpaceStatus是DIDSpaceStatus枚举的别名。
后续步骤
既然您已经熟悉了核心数据结构,就可以探索它们是如何在主要组件中作为属性使用的: