fortify2-js
Version:
MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.
67 lines (64 loc) • 1.85 kB
JavaScript
import { NehoID } from 'nehoid';
/**
* Utility functions for Fortified Function Core
*/
class FortifiedUtils {
/**
* Generate unique execution ID
*/
static generateExecutionId(prefix) {
return 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;
}
}
export { FortifiedUtils };
//# sourceMappingURL=utils.js.map