UNPKG

anon-identity

Version:

Decentralized identity framework with DIDs, Verifiable Credentials, and privacy-preserving selective disclosure

179 lines 5.72 kB
"use strict"; /** * MCP Security Module Exports * * Consolidates all security components for the MCP system */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SecurityConfigBuilder = exports.RateLimitWindow = exports.RateLimiterManager = exports.AuditEventType = exports.AuditLogger = exports.AuthManager = exports.CredentialManager = void 0; exports.createDevelopmentSecurity = createDevelopmentSecurity; exports.createProductionSecurity = createProductionSecurity; var credential_manager_1 = require("./credential-manager"); Object.defineProperty(exports, "CredentialManager", { enumerable: true, get: function () { return credential_manager_1.CredentialManager; } }); var auth_manager_1 = require("./auth-manager"); Object.defineProperty(exports, "AuthManager", { enumerable: true, get: function () { return auth_manager_1.AuthManager; } }); var audit_logger_1 = require("./audit-logger"); Object.defineProperty(exports, "AuditLogger", { enumerable: true, get: function () { return audit_logger_1.AuditLogger; } }); Object.defineProperty(exports, "AuditEventType", { enumerable: true, get: function () { return audit_logger_1.AuditEventType; } }); var rate_limiter_1 = require("./rate-limiter"); Object.defineProperty(exports, "RateLimiterManager", { enumerable: true, get: function () { return rate_limiter_1.RateLimiterManager; } }); Object.defineProperty(exports, "RateLimitWindow", { enumerable: true, get: function () { return rate_limiter_1.RateLimitWindow; } }); /** * Security configuration builder */ class SecurityConfigBuilder { constructor() { this.credentialConfig = { storage: 'memory', encryption: true, rotation: { enabled: false, interval: 30 * 24 * 60 * 60 * 1000, // 30 days retentionCount: 3 }, validation: { validateOnLoad: true, validateOnUse: false, cacheValidation: true } }; this.authConfig = { method: 'api_key', tokenExpiration: 3600000, // 1 hour refreshTokenExpiration: 86400000, // 24 hours multiFactorEnabled: false, sessionTimeout: 1800000 // 30 minutes }; this.authzConfig = { enableRBAC: true, enableABAC: false, defaultDeny: true, agentPermissions: new Map(), resourceAccess: { rules: [], defaultAction: 'deny' } }; this.auditConfig = { enabled: true, logAllRequests: true, logResponses: false, logSensitiveData: false, retentionPeriod: 90 * 24 * 60 * 60 * 1000, // 90 days exportFormat: ['json'] }; } /** * Enable credential encryption */ withEncryption(enabled = true) { this.credentialConfig.encryption = enabled; return this; } /** * Enable credential rotation */ withRotation(interval, retentionCount = 3) { this.credentialConfig.rotation = { enabled: true, interval, retentionCount }; return this; } /** * Set authentication method */ withAuthentication(method, tokenExpiration) { this.authConfig.method = method; if (tokenExpiration) { this.authConfig.tokenExpiration = tokenExpiration; } return this; } /** * Enable MFA */ withMFA(enabled = true) { this.authConfig.multiFactorEnabled = enabled; return this; } /** * Enable RBAC */ withRBAC(enabled = true) { this.authzConfig.enableRBAC = enabled; return this; } /** * Enable ABAC */ withABAC(enabled = true) { this.authzConfig.enableABAC = enabled; return this; } /** * Set default deny policy */ withDefaultDeny(enabled = true) { this.authzConfig.defaultDeny = enabled; return this; } /** * Enable audit logging */ withAuditLogging(config) { Object.assign(this.auditConfig, config); return this; } /** * Build security configuration */ build() { return { credentialConfig: this.credentialConfig, authConfig: this.authConfig, authzConfig: this.authzConfig, auditConfig: this.auditConfig }; } } exports.SecurityConfigBuilder = SecurityConfigBuilder; /** * Create a pre-configured security setup for development */ function createDevelopmentSecurity() { return new SecurityConfigBuilder() .withEncryption(false) .withAuthentication('api_key') .withRBAC(true) .withDefaultDeny(false) .withAuditLogging({ logAllRequests: true, logResponses: true, logSensitiveData: true, retentionPeriod: 7 * 24 * 60 * 60 * 1000 // 7 days }) .build(); } /** * Create a pre-configured security setup for production */ function createProductionSecurity() { return new SecurityConfigBuilder() .withEncryption(true) .withRotation(30 * 24 * 60 * 60 * 1000) // 30 days .withAuthentication('oauth2', 3600000) // 1 hour .withMFA(true) .withRBAC(true) .withABAC(true) .withDefaultDeny(true) .withAuditLogging({ logAllRequests: true, logResponses: false, logSensitiveData: false, retentionPeriod: 90 * 24 * 60 * 60 * 1000 // 90 days }) .build(); } //# sourceMappingURL=index.js.map