xypriss-security
Version:
XyPriss Security is an advanced JavaScript security library designed for enterprise applications. It provides military-grade encryption, secure data structures, quantum-resistant cryptography, and comprehensive security utilities for modern web applicatio
77 lines (73 loc) • 2.18 kB
JavaScript
;
var nehoid = require('nehoid');
/**
* Utility functions for Fortified Function Core
*/
class FortifiedUtils {
constructor() {
// Optimized caches with LRU eviction**
this.FUNCTION_CACHE = new Map();
this.EXECUTION_STATS = new Map();
// Performance-critical function tracking**
this.HOT_FUNCTIONS = new Set();
this.CACHE_SIZE_LIMIT = 1000;
}
/**
* Generate unique execution ID
*/
static generateExecutionId(prefix) {
return nehoid.NehoID.generate({ prefix: "nehonix.func.exec" });
}
/**
* Get current memory usage
*/
static getCurrentMemoryUsage() {
// Simplified memory usage calculation
return process.memoryUsage?.()?.heapUsed || 0;
}
/**
* Sanitize stack trace to remove sensitive parameter information
*/
static sanitizeStackTrace(stack) {
// Remove sensitive parameter information from stack traces
return stack.replace(/\(.*?\)/g, "([REDACTED])");
}
/**
* Sleep utility for retry delays
*/
static sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**
* Calculate exponential backoff delay
*/
static calculateRetryDelay(attempt, maxDelay) {
return Math.min(1000 * Math.pow(2, attempt), maxDelay);
}
/**
* Check if memory usage exceeds limit
*/
static isMemoryLimitExceeded(current, limit) {
return current > limit;
}
/**
* Serialize arguments for hashing (with redaction for large values)
*/
static serializeArgsForHash(args) {
return JSON.stringify(args, (_key, value) => {
// Don't include actual sensitive values in hash
if (typeof value === "string" && value.length > 50) {
return `[REDACTED:${value.length}]`;
}
return value;
});
}
/**
* Check if cache entry is expired
*/
static isCacheEntryExpired(timestamp, maxAge) {
return Date.now() - timestamp > maxAge;
}
}
exports.FortifiedUtils = FortifiedUtils;
//# sourceMappingURL=utils.js.map