UNPKG

nucypher-experimental-taco-storage

Version:

TypeScript SDK for encrypted data storage with TACo (Threshold Access Control), supporting multiple storage providers including IPFS and SQLite

106 lines 3.65 kB
/** * Base storage adapter interface and abstract implementation */ import { AdapterConfig, StorageMetadata, StorageResult } from '../types'; /** * Base interface that all storage adapters must implement */ export interface IStorageAdapter { /** * Initialize the storage adapter * @returns Promise that resolves when initialization is complete */ initialize(): Promise<void>; /** * Store encrypted data with metadata * @param encryptedData - The encrypted data to store * @param metadata - Metadata associated with the data * @returns Promise resolving to storage result */ store(encryptedData: Uint8Array, metadata: StorageMetadata): Promise<StorageResult>; /** * Retrieve encrypted data by ID * @param id - Unique identifier for the data * @returns Promise resolving to the encrypted data and metadata */ retrieve(id: string): Promise<{ encryptedData: Uint8Array; metadata: StorageMetadata; }>; /** * Delete stored data by ID * @param id - Unique identifier for the data * @returns Promise resolving to success status */ delete(id: string): Promise<boolean>; /** * Check if data exists by ID * @param id - Unique identifier for the data * @returns Promise resolving to existence status */ exists(id: string): Promise<boolean>; /** * List all stored data IDs (optional, for adapters that support it) * @param limit - Maximum number of IDs to return * @param offset - Number of IDs to skip * @returns Promise resolving to array of IDs */ list?(limit?: number, offset?: number): Promise<string[]>; /** * Get adapter-specific health/status information * @returns Promise resolving to health status */ getHealth(): Promise<{ healthy: boolean; details?: Record<string, unknown>; }>; /** * Clean up resources when adapter is no longer needed */ cleanup(): Promise<void>; } /** * Abstract base class providing common functionality for storage adapters */ export declare abstract class BaseStorageAdapter implements IStorageAdapter { protected readonly config: AdapterConfig; constructor(config: AdapterConfig); /** * Validate that required configuration is present * @param requiredKeys - Array of required configuration keys * @throws Error if required configuration is missing */ protected validateConfig(requiredKeys: string[]): void; /** * Generate a unique storage reference for the adapter * @param id - The data ID * @returns Adapter-specific reference string */ protected abstract generateReference(id: string): string; /** * Validate data ID format * @param id - The ID to validate * @throws Error if ID format is invalid */ protected validateId(id: string): void; /** * Validate encrypted data * @param data - The data to validate * @throws Error if data is invalid */ protected validateData(data: Uint8Array): void; abstract initialize(): Promise<void>; abstract store(encryptedData: Uint8Array, metadata: StorageMetadata): Promise<StorageResult>; abstract retrieve(id: string): Promise<{ encryptedData: Uint8Array; metadata: StorageMetadata; }>; abstract delete(id: string): Promise<boolean>; abstract exists(id: string): Promise<boolean>; abstract getHealth(): Promise<{ healthy: boolean; details?: Record<string, unknown>; }>; abstract cleanup(): Promise<void>; } //# sourceMappingURL=base.d.ts.map