本節為整個 DID Space 元件庫中使用的核心 TypeScript 類型和介面提供詳細參考。理解這些資料結構對於在您的應用程式中正確鍵入元件 props 和管理狀態至關重要。
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 等元件渲染空間詳細資訊的關鍵 prop。
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
// 為了相容性
export type SpaceGateway = DIDSpaceGateway;
export const SpaceStatus = DIDSpaceStatus;SpaceGateway是DIDSpaceGateway的別名。SpaceStatus是DIDSpaceStatus列舉的別名。
後續步驟
既然您已熟悉核心資料結構,您可以探索它們如何在主要元件中作為 props 使用: