UNPKG

@kya-os/mcp-i

Version:

COMING SOON:Production-ready MCP Identity with automatic registration, key rotation, and optimized performance

48 lines 1.58 kB
/** * Encrypted storage wrapper for MCP-I identity * Adds encryption layer on top of any storage provider */ import * as crypto from './crypto.js'; export class EncryptedStorage { baseStorage; password; constructor(baseStorage, password) { this.baseStorage = baseStorage; this.password = password; } async load() { const identity = await this.baseStorage.load(); if (!identity) { return null; } // Decrypt private key if encrypted if (identity.privateKey.startsWith('enc:')) { try { identity.privateKey = await crypto.decrypt(identity.privateKey, this.password); } catch (error) { throw new Error('Failed to decrypt stored identity - invalid password'); } } return identity; } async save(identity) { // Create a copy to avoid modifying the original const encryptedIdentity = { ...identity }; // Encrypt private key before saving if (!encryptedIdentity.privateKey.startsWith('enc:')) { encryptedIdentity.privateKey = await crypto.encrypt(encryptedIdentity.privateKey, this.password); } await this.baseStorage.save(encryptedIdentity); } async exists() { return this.baseStorage.exists(); } } /** * Create encrypted storage wrapper */ export function createEncryptedStorage(baseStorage, password) { return new EncryptedStorage(baseStorage, password); } //# sourceMappingURL=encrypted-storage.js.map