Files
identity/implementations/AsyncStorageAdapter.ts
Chris Daßler a6b10428fa Initial commit: Identity management component
- Hierarchical user/device identity system with HD key derivation
- Dependency injection for AsyncStorage and Platform
- Self-contained TypeScript declarations
- Ed25519 keypairs managed by IdentityManager
- Deterministic peer ID generation from BIP39 mnemonic
2025-08-29 14:17:39 +02:00

44 lines
1.2 KiB
TypeScript

/**
* AsyncStorage adapter for React Native
*/
import type { IIdentityStorage } from '../interfaces/IIdentity';
// AsyncStorage type definition for dependency injection
interface IAsyncStorage {
setItem(key: string, value: string): Promise<void>;
getItem(key: string): Promise<string | null>;
removeItem(key: string): Promise<void>;
getAllKeys(): Promise<string[]>;
multiRemove(keys: string[]): Promise<void>;
}
export class AsyncStorageAdapter implements IIdentityStorage {
private asyncStorage: IAsyncStorage;
constructor(asyncStorage: IAsyncStorage) {
this.asyncStorage = asyncStorage;
}
async setItem(key: string, value: string): Promise<void> {
await this.asyncStorage.setItem(key, value);
}
async getItem(key: string): Promise<string | null> {
return await this.asyncStorage.getItem(key);
}
async removeItem(key: string): Promise<void> {
await this.asyncStorage.removeItem(key);
}
async clear(): Promise<void> {
// Only clear identity-related keys
const keys = await this.asyncStorage.getAllKeys();
const identityKeys = keys.filter((key) => key.startsWith('@IdentityManager'));
if (identityKeys.length > 0) {
await this.asyncStorage.multiRemove(identityKeys);
}
}
}