@lightninglabs/lnc-web
Version:
Lightning Node Connect npm module for web
107 lines • 3.38 kB
TypeScript
import { UnlockOptions } from '../types/lightningNodeConnect';
/**
* Interface for credential repositories that manage how encrypted credentials are stored
* and retrieved. The base class handles localStorage operations (serializing all
* credentials under a single namespaced key) while subclasses manage the unlock/lock
* lifecycle specific to their encryption method.
*/
export interface CredentialRepository {
/**
* Check if the repository is unlocked
*/
get isUnlocked(): boolean;
/**
* Check if any credentials exist (sync for performance)
*/
get hasAnyCredentials(): boolean;
/**
* Get a decrypted credential value (async due to encryption/decryption)
*/
getCredential(key: string): Promise<string | undefined>;
/**
* Set an encrypted credential value (async due to encryption)
*/
setCredential(key: string, value: string): Promise<void>;
/**
* Remove a credential (async for consistency and future extensibility)
* Default implementation provided in BaseCredentialRepository
*/
removeCredential(key: string): Promise<void>;
/**
* Check if a credential exists (sync for performance)
*/
hasCredential(key: string): boolean;
/**
* Unlock the repository for encryption/decryption
*/
unlock(options: UnlockOptions): Promise<void>;
/**
* Lock the repository (clear sensitive data)
*/
lock(): void;
/**
* Clear all stored credentials
*/
clear(): void;
}
/**
* Base class for credential repositories with common localStorage functionality
*/
export declare abstract class BaseCredentialRepository implements CredentialRepository {
protected namespace: string;
/**
* The credentials stored in memory for quick access after loading from storage
*/
private credentials;
constructor(namespace: string);
abstract get isUnlocked(): boolean;
abstract getCredential(key: string): Promise<string | undefined>;
abstract setCredential(key: string, value: string): Promise<void>;
abstract unlock(options: UnlockOptions): Promise<void>;
abstract lock(): void;
/**
* Check if any credentials are stored
*/
get hasAnyCredentials(): boolean;
/**
* Remove a credential by key. This is async for consistency and future extensibility.
*/
removeCredential(key: string): Promise<void>;
/**
* Check if a credential exists by key
*/
hasCredential(key: string): boolean;
/**
* Clear all credentials
*/
clear(): void;
/**
* Get the storage key for the repository
*/
private get storageKey();
/**
* Get the credentials, loading them from storage if they are not already loaded
*/
private get loadedCredentials();
/**
* Get a credential by key
*/
protected get(key: string): string | undefined;
/**
* Set a credential by key
*/
protected set(key: string, value: string): void;
/**
* Remove a credential by key
*/
protected remove(key: string): void;
/**
* Save all credentials to storage as a JSON string under a single key
*/
private save;
/**
* Load all credentials from storage as a JSON string under a single key
*/
private load;
}
//# sourceMappingURL=credentialRepository.d.ts.map