/** * Public Key Directory Service for the BrightChain identity system. * * Provides an in-memory searchable directory of member public profiles. * Supports search by display name, social username, or member ID with * relevance ranking, pagination, and platform filtering. Members may * opt out of directory listing via privacy mode. * * Follows the same stateful-service pattern used by * {@link MemberPaperKeyService}, {@link ConversationService}, and other * BrightChain services that manage in-memory state with `Map`s. * * Requirements: 5.1, 5.2, 5.3, 5.6, 5.9 */ import { ProofPlatform } from '../../enumerations/proofPlatform'; import { IPublicProfile } from '../../interfaces/identity/publicProfile'; /** * Error thrown when a profile operation references a member that does not exist. */ export declare class ProfileNotFoundError extends Error { constructor(memberId: string); } /** * Error thrown when a profile update is missing required fields. */ export declare class InvalidProfileError extends Error { constructor(message: string); } /** * Options for controlling directory search behaviour. * * Supports pagination (Requirement 5.5) and platform filtering * (Requirement 5.10). */ export interface ISearchOptions { /** Maximum number of results to return. Defaults to 20. */ limit?: number; /** Zero-based offset for pagination. Defaults to 0. */ offset?: number; /** * Filter results to only include profiles with a verified proof * on the specified platform (Requirement 5.10). */ platformFilter?: ProofPlatform; } /** * A single search result with its relevance score. * * Requirement 5.3: Search results include relevance ranking. */ export interface ISearchResult { /** The matched public profile */ profile: IPublicProfile; /** Relevance score (higher is more relevant). Used for ranking. */ relevanceScore: number; } /** * Paginated search response. */ export interface ISearchResponse { /** The matched profiles, ordered by descending relevance score */ results: ISearchResult[]; /** Total number of matching profiles (before pagination) */ totalCount: number; /** Whether there are more results beyond the current page */ hasMore: boolean; } /** * In-memory public key directory for searching and managing member profiles. * * The directory stores {@link IPublicProfile} records keyed by member ID * and provides full-text search across display names, social usernames, * and member IDs with relevance-based ranking. * * Privacy mode (Requirement 5.6, 5.9): Profiles with `privacyMode: true` * are excluded from search results but can still be accessed directly * via {@link getProfile}. * * @example * ```typescript * const directory = new PublicKeyDirectoryService(); * * // Add a profile * directory.updateProfile({ * memberId: 'member-xyz', * displayName: 'Alice', * publicKey: '04abcdef...', * identityProofs: [], * createdAt: new Date(), * updatedAt: new Date(), * privacyMode: false, * }); * * // Search for profiles * const results = directory.search('Alice'); * * // Toggle privacy mode * directory.togglePrivacyMode('member-xyz'); * ``` */ export declare class PublicKeyDirectoryService { /** * Profile storage keyed by member ID. */ private readonly profiles; /** * Search the directory for profiles matching the given query. * * Searches across display names, social usernames from identity proofs, * and member IDs. Results are ranked by relevance score (Requirement 5.3). * * Profiles in privacy mode are excluded from results (Requirement 5.9). * Only verified identity proofs are considered for username matching * (Requirement 5.4). * * **Validates: Requirements 5.2, 5.3, 5.5, 5.9, 5.10** * * @param query - The search query string (case-insensitive) * @param options - Optional search parameters (pagination, filtering) * @returns Paginated search results ordered by descending relevance */ search(query: string, options?: ISearchOptions): ISearchResponse; /** * Get a profile by member ID. * * Unlike {@link search}, this method returns profiles regardless of * privacy mode. This allows existing contacts to look up a member * directly even when the member has opted out of directory listing. * * **Validates: Requirements 5.1, 5.9** * * @param memberId - The member ID to look up * @returns The public profile * @throws {ProfileNotFoundError} If no profile exists for the member ID */ getProfile(memberId: string): IPublicProfile; /** * Add or update a profile in the directory. * * If a profile already exists for the member ID, it is replaced. * The `updatedAt` timestamp is set to the current time on update. * * **Validates: Requirements 5.1, 5.8** * * @param profile - The public profile to store * @throws {InvalidProfileError} If required fields are missing */ updateProfile(profile: IPublicProfile): void; /** * Toggle privacy mode for a member's profile. * * When privacy mode is enabled, the profile is excluded from search * results (Requirement 5.9) but can still be accessed directly via * {@link getProfile}. * * **Validates: Requirements 5.6, 5.9** * * @param memberId - The member whose privacy mode to toggle * @returns The new privacy mode state (`true` = private, `false` = public) * @throws {ProfileNotFoundError} If no profile exists for the member ID */ togglePrivacyMode(memberId: string): boolean; /** * Get the total number of profiles in the directory. */ get size(): number; /** * Check whether a profile exists for the given member ID. */ hasProfile(memberId: string): boolean; /** * Remove a profile from the directory. * * @param memberId - The member whose profile to remove * @returns `true` if a profile was removed, `false` if none existed */ removeProfile(memberId: string): boolean; /** * Remove all profiles from the directory. * Useful for testing. */ clear(): void; /** * Calculate the relevance score for a profile against a search query. * * Scoring strategy (Requirement 5.3): * - Exact member ID match: highest score * - Exact display name match: high score * - Display name prefix match: medium-high score * - Exact social username match: high score * - Social username prefix match: medium score * - Substring matches: lower scores * - Bonus for each verified identity proof * * Only verified proofs are considered for username matching * (Requirement 5.4). * * @param profile - The profile to score * @param normalizedQuery - The lowercase, trimmed search query * @returns The relevance score (0 means no match) */ private calculateRelevanceScore; /** * Validate that a profile has all required fields. * * @throws {InvalidProfileError} If validation fails */ private validateProfile; } //# sourceMappingURL=publicKeyDirectoryService.d.ts.map