UNPKG

@nuwa-ai/identity-kit-web

Version:

Web extensions for Nuwa Identity Kit

76 lines (75 loc) 2.39 kB
import { KeyManager, NIP1SignedObject, VDRRegistry, SignedData } from '@nuwa-ai/identity-kit'; import { DeepLinkManager } from './deeplink/DeepLinkManager'; export interface IdentityKitWebOptions { /** Application name, used to build key id fragment; optional */ appName?: string; cadopDomain?: string; storage?: 'local' | 'indexeddb' | 'memory'; keyManager?: KeyManager; deepLinkManager?: DeepLinkManager; /** Optional explicit RPC endpoint for Rooch node */ roochRpcUrl?: string; } /** * IdentityKitWeb – High-level Web SDK for Nuwa Identity Kit * Provides a high-level API for web applications */ export declare class IdentityKitWeb { private keyManager; private deepLinkManager; private cadopDomain; private appName?; private constructor(); /** * Initialize the IdentityKitWeb */ static init(options?: IdentityKitWebOptions): Promise<IdentityKitWeb>; /** * Check if the user is connected */ isConnected(): Promise<boolean>; /** * Get the current DID */ getDid(): Promise<string>; /** * List all key IDs */ listKeyIds(): Promise<string[]>; /** * Connect to Cadop * This will open a new window with the Cadop add-key page */ connect(): Promise<void>; /** * Handle the callback from Cadop */ handleCallback(search: string): Promise<void>; /** * Sign an operation payload using DIDAuth v1 * @param payload Object containing `operation` and `params` fields (other fields will be added automatically) */ sign(payload: Omit<SignedData, 'nonce' | 'timestamp'>): Promise<NIP1SignedObject>; /** * Verify a signature */ verify(sig: NIP1SignedObject, opts?: { maxClockSkew?: number; }): Promise<boolean>; /** * Logout (clear all keys) */ logout(): Promise<void>; /** * Generate a readable idFragment based on the application name. * 1. Slugify the provided appName (keep a-z, 0-9, _ and -) * 2. If slug becomes empty (e.g. non-Latin name), fall back to current hostname * 3. If hostname slug is still empty (edge case), use default 'key' * Always append timestamp to ensure uniqueness. */ private generateIdFragment; /** * Expose the global VDRRegistry instance */ static get registry(): VDRRegistry; }