/** * Identity Management Interfaces * * Provides hierarchical user/device identity management with HD key derivation */ /** * User identity (master identity) */ export interface UserIdentity { userId: string; // Hash of master public key publicKey: Uint8Array; // Master public key mnemonic?: string; // Stored securely, only on this device } /** * Device identity (derived from user) */ export interface DeviceIdentity { deviceId: string; // libp2p peer ID deviceName: string; // Human-readable name publicKey: Uint8Array; // Device public key (Ed25519) privateKey: Uint8Array; // Device private key (Ed25519) derivationPath: string; // HD derivation path createdAt: number; lastSeen?: number; } /** * Device information for remote devices */ export interface DeviceInfo { deviceId: string; deviceName: string; multiaddrs: string[]; isOnline: boolean; lastSeen: number; } /** * Configuration for identity manager */ export interface IdentityConfig { storagePrefix?: string; mnemonicStrength?: 128 | 160 | 192 | 224 | 256; deviceNameProvider?: () => Promise; } /** * Main identity management interface */ export interface IIdentityManager { /** * Initialize the identity manager * Either loads existing identity or creates new one */ initialize(): Promise; /** * Create a completely new user identity with mnemonic */ createNewIdentity(): Promise; /** * Restore identity from mnemonic phrase */ restoreFromMnemonic(mnemonic: string): Promise; /** * Create a new device identity derived from master */ createDeviceIdentity(deviceName: string): Promise; /** * Get current device identity or create one if none exists */ getCurrentDevice(): Promise; /** * List all registered devices for this user */ getRegisteredDevices(): Promise; /** * Remove a device from the user's identity */ removeDevice(deviceId: string): Promise; /** * Clean up duplicate devices with the same base name * @returns Number of devices removed */ cleanupDuplicateDevices(): Promise; /** * Clean up inactive devices (except current device) * @param daysInactive - Number of days of inactivity before removal (default: 30) * @returns Number of devices removed */ cleanupInactiveDevices(daysInactive?: number): Promise; /** * Get the libp2p keypair for current device */ getLibp2pKeypair(): Promise<{ privateKey: Uint8Array; publicKey: Uint8Array }>; /** * Update the current device's peer ID after libp2p generates it */ updateDevicePeerId(peerId: string): Promise; /** * Calculate what the peer ID will be for a given device index * Useful during pairing to predict the new device's peer ID */ calculatePeerIdForIndex(deviceIndex: number): Promise; /** * Export mnemonic for backup (should be done securely!) */ getMnemonic(): string | undefined; /** * Get user identity */ getUserIdentity(): UserIdentity | undefined; /** * Check if identity is initialized */ isInitialized(): boolean; /** * Clear all identity data (dangerous!) */ reset(): Promise; /** * Broadcast peer ID update to other devices */ broadcastPeerIdUpdate( oldPeerId: string, newPeerId: string, sendProtocolData?: (peerId: string, protocolId: string, data: Uint8Array) => Promise, ): Promise; } /** * Storage interface for identity persistence */ export interface IIdentityStorage { setItem(key: string, value: string): Promise; getItem(key: string): Promise; removeItem(key: string): Promise; clear(): Promise; } /** * Factory for creating identity manager instances */ export interface IIdentityFactory { create(config?: IdentityConfig): IIdentityManager; }