🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

fortify2-js

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fortify2-js

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.

4.5.10
latest
Source
npm
Version published
Weekly downloads
1.2K
3.95%
Maintainers
1
Weekly downloads
 
Created
Source

Nehonix FortifyJS - Advanced JavaScript Security Library

FortifyJS is a robust JavaScript security library designed to enhance data structures with advanced cryptographic features, real-time security, and type safety. It provides a comprehensive set of tools for secure data handling, featuring the world's most advanced SecureArray implementation with military-grade encryption and real-time monitoring.

Why Choose FortifyJS?

FortifyJS empowers developers to create secure, type-safe, and chainable JavaScript objects with advanced cryptographic capabilities. Key advantages include:

  • Enhanced Object Methods: 19 powerful methods for data manipulation, surpassing standard JavaScript objects.
  • Advanced Security: Implements military-grade cryptography with quantum-resistant algorithms.
  • Type Safety: Full TypeScript support for robust, error-free development.

Comparison with Standard Objects

FeatureStandard ObjectFortifyJS SecureObject
MethodsNone19 Enhanced Methods
Type SafetyBasicFull TypeScript Support
SecurityNoneAdvanced Cryptography
ChainingNot SupportedFully Chainable API
EventsNot SupportedEvent-Driven Operations
Memory SafetyManualAutomatic Cleanup

Comparison with Lodash

FeatureLodashFortifyJS
SecurityNoneBuilt-In Cryptography
Type SafetyPartialFull TypeScript Support
Memory ManagementManualAutomatic
Sensitive DataNot SupportedSecurity-Aware Filtering
EventsNot SupportedOperation Tracking

Testing and Validation

  • 100% integration test coverage (14/14 tests passed)
  • Validated security features
  • Verified performance benchmarks
  • Optimized memory usage

Key Features

⚡ FortifiedFunction - Ultra-Fast Secure Function Wrapper

A high-performance, security-enhanced function wrapper that provides intelligent caching, comprehensive monitoring, and configurable security features with ultra-fast execution modes.

Performance Breakthrough: Optimized from 109+ seconds to 1-4ms execution time - a 27,000x performance improvement.

Performance Modes

ModeExecution TimePerformance GainUse Case
Ultra-Fast1-4ms27,000x fasterHot paths, API routes
Standard20-50ms2,000x fasterBusiness logic
Secure100-200ms500x fasterSensitive operations

Quick Start

import { func } from "fortify2-js";

// Ultra-fast mode for performance-critical paths
const ultraFastFunction = func(
    async (data) => {
        return processData(data);
    },
    { ultraFast: "minimal" }
);

// Standard balanced mode (default)
const standardFunction = func(async (data) => {
    return processData(data);
});

// Secure mode for sensitive operations
const secureFunction = func(
    async (data) => {
        return processData(data);
    },
    {
        autoEncrypt: true,
        auditLog: true,
        detailedMetrics: true,
    }
);

🔒 SecureArray - World's Most Advanced Secure Data Structure

  • Military-Grade Encryption: Real AES-256-CTR-HMAC with 77.98 bits entropy
  • Real-Time Monitoring: Live memory usage, access tracking, and performance metrics
  • Snapshot Management: Version control with create, restore, and rollback capabilities
  • Event System: Comprehensive event handling for all array operations
  • Advanced Operations: unique(), shuffle(), min(), max(), compact() with security
  • Multiple Export Formats: JSON, CSV, XML, YAML with integrity verification
  • Memory Management: Automatic cleanup, leak detection, and secure wiping
  • 100+ Methods: Full JavaScript Array API compatibility plus security features

SecureRandom with Encoding Support

  • Supports multiple encodings: hex, base64, base64url, base58, binary, utf8
  • Utilizes cryptographically secure pseudorandom number generators (CSPRNG)
  • Cross-platform compatibility for Node.js and browsers
  • Quantum-safe random generation options
  • Built-in entropy quality assessment

RSA Key Calculator & Generator

  • Calculates optimal RSA key sizes based on data requirements
  • Provides comprehensive security assessments
  • Supports multiple hash algorithms (SHA-256, SHA-384, SHA-512)
  • Offers hybrid encryption recommendations
  • Includes performance benchmarking

Password Management System

  • Implements Argon2ID, Argon2I, and Argon2D algorithms
  • Provides military-grade hashing with timing-safe verification
  • Supports seamless migration from bcrypt
  • Includes password strength analysis with entropy calculation
  • Achieves hash/verify times of 674-995ms for optimal security

Advanced Security Features

  • Secure memory management with buffer protection
  • Resistance to side-channel attacks
  • Quantum-resistant cryptographic algorithms
  • Support for hardware security modules (HSMs)
  • Real-time security monitoring

Installation

Install FortifyJS via npm:

npm install fortify2-js

Optional Security Packages

For enhanced cryptographic functionality, install:

npm install @noble/hashes @noble/ciphers libsodium-wrappers argon2 bcryptjs

Quick Start

SecureArray - Military-Grade Secure Data Structure

import { fArray } "fortify2-js"

// Create a secure array with AES-256-CTR-HMAC encryption
const secureData = fArray(["sensitive-data", "api-keys", "user-info"]);

// Set encryption key
secureData.setEncryptionKey("your-super-secret-key-2025");

// Encrypt all data with military-grade security
secureData.encryptAll();

// Use like a regular array - data is automatically encrypted/decrypted
secureData.push("new-secret");
const firstItem = secureData.get(0); // Automatically decrypted
const filtered = secureData.filter((item) => item.includes("api"));

// Advanced features
const snapshot = secureData.createSnapshot(); // Version control
const stats = secureData.getStats(); // Real-time monitoring
const exported = secureData.exportData("csv"); // Multiple export formats

// Event system
secureData.on("push", (data) => console.log("New item added securely"));

// Comprehensive security status
const status = secureData.getEncryptionStatus();
console.log(status.algorithm); // "AES-256-CTR-HMAC"

Password Management

import { PasswordManager } from "fortify2-js";

// or import pm directly
// import { pm } from "fortify2-js"; //NOTE: pm uses default configuration, for custom config, use PasswordManager.create() or PasswordManager.getInstance()

const pm = PasswordManager.getInstance();

// Generate a secure password
const password = pm.generateSecurePassword(16, {
    includeUppercase: true,
    includeLowercase: true,
    includeNumbers: true,
    includeSymbols: true,
});
console.log("Generated password:", password);

// Analyze password strength
const analysis = pm.analyzeStrength("MyPassword123!");
console.log("Strength score:", analysis.score);
console.log("Entropy:", analysis.entropy);

// Hash password with Argon2ID
const hash = await pm.hash("MyPassword123!", {
    algorithm: "argon2id",
    securityLevel: "high",
});
console.log("Secure hash:", hash);

// Verify password
const verification = await pm.verify("MyPassword123!", hash);
console.log("Valid password:", verification.isValid);
console.log("Security level:", verification.securityLevel);

SecureRandom with Encoding

import { SecureRandom } from "fortify2-js";
// or use: import { Random } from "fortify2-js";

const randomBytes = SecureRandom.getRandomBytes(32);

// Multiple encoding options
console.log("Hex:", randomBytes.toString("hex"));
console.log("Base64:", randomBytes.toString("base64"));
console.log("Base64URL:", randomBytes.toString("base64url"));
console.log("Base58:", randomBytes.toString("base58"));

// Entropy information
console.log("Entropy Info:", randomBytes.getEntropyInfo());

RSA Key Calculator & Generator

import {
    calculateRSAKeySize,
    generateRSAKeyPairForData,
    validateDataSizeForRSAKey,
    getRSARecommendations,
    assessRSASecurity,
} from "fortify2-js";

const dataSize = 190; // bytes
const keySize = calculateRSAKeySize(dataSize, "sha256");
console.log(`Recommended key size: ${keySize} bits`);

const keyPair = generateRSAKeyPairForData(dataSize, "sha256");
console.log("Public Key:", keyPair.publicKey);
console.log("Max Data Size:", keyPair.maxDataSize);

const validation = validateDataSizeForRSAKey(dataSize, 2048, "sha256");
console.log("Valid:", validation.valid);
console.log("Recommendation:", validation.recommendation);

const recommendations = getRSARecommendations(dataSize);
recommendations.forEach((rec) => {
    console.log(`${rec.keySize}-bit: ${rec.recommendation}`);
});

const security = assessRSASecurity(2048, "sha256", dataSize);
console.log("Security Level:", security.level);
console.log("Security Score:", security.score);
console.log("NIST Compliant:", security.compliance.nist);

FortifiedFunction - Comprehensive Guide

Overview

FortifiedFunction transforms ordinary functions into secure, monitored, and optimized execution units. It provides multiple performance modes ranging from ultra-fast execution (1-4ms) to comprehensive security monitoring, making it suitable for both performance-critical applications and security-sensitive environments.

Configuration Options

Performance Options

interface PerformanceOptions {
    ultraFast?: "minimal" | "standard" | "maximum" | boolean;
    memoize?: boolean; // Enable result caching
    timeout?: number; // Execution timeout (ms)
    retries?: number; // Retry attempts
    maxRetryDelay?: number; // Maximum retry delay (ms)
    smartCaching?: boolean; // Intelligent cache management
    cacheStrategy?: "adaptive" | "lru" | "fifo";
    cacheTTL?: number; // Cache time-to-live (ms)
    maxCacheSize?: number; // Maximum cache entries
    optimizeExecution?: boolean; // Enable execution optimizations
}

Security Options

interface SecurityOptions {
    autoEncrypt?: boolean; // Automatic parameter encryption
    secureParameters?: (string | number)[]; // Parameters to encrypt
    memoryWipeDelay?: number; // Memory cleanup delay (ms)
    stackTraceProtection?: boolean; // Sanitize stack traces
    smartSecurity?: boolean; // Advanced security features
    threatDetection?: boolean; // Real-time threat detection
}

Monitoring Options

interface MonitoringOptions {
    auditLog?: boolean; // Enable audit logging
    performanceTracking?: boolean; // Track performance metrics
    debugMode?: boolean; // Enable debug output
    detailedMetrics?: boolean; // Comprehensive metrics
    anomalyDetection?: boolean; // Detect unusual patterns
    performanceRegression?: boolean; // Monitor performance degradation
}

Performance Mode Details

Ultra-Fast Mode (ultraFast: 'minimal')

Optimized for maximum performance with minimal overhead:

  • Target: <10ms execution time
  • Achieved: 1-4ms actual performance
  • Features: Direct execution bypass, object pooling, fast cache keys
  • Security: Minimal (stack trace protection only)
  • Monitoring: Disabled for maximum speed
const hotPath = func(criticalFunction, {
    ultraFast: "minimal",
    memoize: true,
    cacheTTL: 300000,
});

Standard Mode (Default)

Balanced performance and functionality for typical production use:

  • Target: <50ms execution time
  • Features: Smart caching, performance tracking, audit logging
  • Security: Stack trace protection, basic monitoring
  • Monitoring: Essential metrics enabled
const businessLogic = func(regularFunction, {
    // Uses optimized defaults
    memoize: true,
    smartCaching: true,
    auditLog: true,
});

Secure Mode

Maximum security and comprehensive monitoring:

  • Target: <200ms execution time
  • Features: Full encryption, detailed metrics, threat detection
  • Security: Complete security suite enabled
  • Monitoring: Comprehensive tracking and analytics
const sensitiveOperation = func(secureFunction, {
    autoEncrypt: true,
    stackTraceProtection: true,
    detailedMetrics: true,
    threatDetection: true,
    anomalyDetection: true,
});

API Reference

Core Methods

execute(...args): Promise<R>

Executes the wrapped function with all configured security and monitoring features.

getStats(): FunctionStats

Returns comprehensive execution statistics including performance metrics and cache statistics.

getCacheStats(): CacheStats

Returns detailed cache performance information including hit rates and memory usage.

clearCache(): void

Clears all cached results and resets cache statistics.

destroy(): void

Properly cleans up all resources, active executions, and event listeners.

Advanced Methods

getOptimizationSuggestions(): OptimizationSuggestion[]

Returns AI-generated suggestions for improving function performance based on execution patterns.

getPerformanceTrends(): PerformanceTrend[]

Returns historical performance data for trend analysis and capacity planning.

warmCache(): void

Pre-populates cache with frequently accessed data for improved response times.

Best Practices

Choosing Performance Modes

Use Ultra-Fast Mode When:

  • Function is called frequently (>1000 times/minute)
  • Response time is critical (<10ms requirement)
  • Security requirements are minimal
  • Function handles non-sensitive data

Use Standard Mode When:

  • Balanced performance and security needed
  • Function handles business logic
  • Debugging capabilities required
  • Moderate call frequency (<100 times/minute)

Use Secure Mode When:

  • Function processes sensitive data
  • Compliance requirements exist
  • Comprehensive audit trails needed
  • Security is prioritized over performance

Performance Optimization Guidelines

  • Enable Caching: Always enable memoize for functions with deterministic outputs
  • Tune Cache TTL: Set appropriate cacheTTL based on data freshness requirements
  • Monitor Metrics: Use performanceTracking to identify bottlenecks
  • Optimize Hot Paths: Apply ultraFast: 'minimal' to frequently called functions
  • Memory Management: Configure maxMemoryUsage based on available system resources

Security Considerations

  • Encryption: Enable autoEncrypt for functions handling PII or sensitive data
  • Audit Logging: Always enable auditLog in production environments
  • Stack Protection: Keep stackTraceProtection enabled to prevent information leakage
  • Threat Detection: Enable in high-security environments with threatDetection

Migration Guide

From Version 1.x

// Old approach
const wrappedFunction = fortify(myFunction, {
    cache: true,
    security: "high",
});

// New approach
const wrappedFunction = func(myFunction, {
    memoize: true,
    autoEncrypt: true,
    auditLog: true,
});

Performance Migration

For existing high-performance requirements:

// Replace performance-critical functions
const optimizedFunction = func(existingFunction, {
    ultraFast: "minimal", // New ultra-fast mode
    memoize: true,
    cacheTTL: 300000,
});

Advanced Usage

Custom Cache Strategies

const customCachedFunction = func(expensiveOperation, {
    smartCaching: true,
    cacheStrategy: "adaptive",
    maxCacheSize: 5000,
    cacheTTL: 600000, // 10 minutes
});

Comprehensive Monitoring

const monitoredFunction = func(businessCriticalFunction, {
    auditLog: true,
    performanceTracking: true,
    detailedMetrics: true,
    anomalyDetection: true,
});

// Access monitoring data
const stats = monitoredFunction.getStats();
const trends = monitoredFunction.getPerformanceTrends();
const suggestions = monitoredFunction.getOptimizationSuggestions();

Event Handling

const eventAwareFunction = func(myFunction, options);

eventAwareFunction.on("execution_success", (data) => {
    console.log(`Function executed successfully in ${data.executionTime}ms`);
});

eventAwareFunction.on("cache_hit", (data) => {
    console.log(`Cache hit for execution ${data.executionId}`);
});

eventAwareFunction.on("performance_warning", (data) => {
    console.warn(`Performance degradation detected: ${data.message}`);
});

Encoding Types

FortifyJS supports various encoding formats:

EncodingUse CaseExample Output
hexDebugginga1b2c3d4e5f6...
base64Data transmissionoWvD1OX2...
base64urlURL-safe tokensoWvD1OX2... (no padding)
base58Cryptocurrency2NEpo7TZR...
binaryRaw binary dataBinary string
utf8Text representationUTF-8 string

RSA Key Size Recommendations

Data SizeRecommended Key SizeSecurity LevelUse Case
≤ 190 bytes2048 bitsStandardAPI keys, tokens
≤ 318 bytes3072 bitsHighCertificates, keys
≤ 446 bytes4096 bitsMaximumHigh-security apps
> 446 bytesHybrid EncryptionOptimalLarge data encryption

Security Levels

Memory Protection Levels

  • Basic: Standard secure wiping
  • Enhanced: Includes fragmentation, encryption, and canaries
  • Military: Adds advanced obfuscation
  • Quantum-Safe: Incorporates quantum-resistant algorithms

RSA Security Assessment

  • Minimal: 2048-bit keys (legacy compatibility)
  • Standard: 3072-bit keys (current standard)
  • High: 4096-bit keys (high-security applications)
  • Maximum: 8192+ bit keys (maximum security)

Performance Benchmarks

FortifiedFunction Performance

ModeExecution TimePerformance GainThroughput (ops/sec)Status
Ultra-Fast1-4ms27,000x faster250-1,000Production Ready
Standard20-50ms2,000x faster20-50Production Ready
Secure100-200ms500x faster5-10Production Ready

Baseline: Original implementation: 109+ seconds per operation

Random Generation Performance

OperationRate (ops/sec)Performance Grade
Random Float Generation2,029,015Excellent
Random Integer Generation1,645,765Excellent
Secure UUID Generation85,259Excellent
Random Bytes (32B)69,485Excellent
Salt Generation (64B)72,654Excellent

Hash Operations Performance

OperationRate (ops/sec)Security Level
SHA-256 Hashing16Military-Grade
SHA-512 Hashing14Military-Grade
BLAKE3 Hashing3Maximum
Hash Verification16Military-Grade

Password Algorithm Performance

AlgorithmHash TimeVerify TimeSecurity LevelStatus
Argon2ID931ms995msHighProduction Ready
Argon2I674ms681msHighProduction Ready
Argon2D737ms740msHighProduction Ready
ScryptTBDTBDStandardIn Development
PBKDF2TBDTBDStandardIn Development
MilitaryTBDTBDMaximumIn Development

SecureArray Performance

OperationRate (ops/sec)Security LevelStatus
Array Creation50,000+Military-GradeProduction Ready
Encrypted Push/Pop25,000+AES-256-CTRProduction Ready
Snapshot Creation10,000+Full StateProduction Ready
Event System100,000+Real-TimeProduction Ready
Memory ManagementAutoLeak DetectionProduction Ready
Serialization (JSON)5,000+CompressedProduction Ready
Export (CSV/XML/YAML)3,000+Multi-FormatProduction Ready
Integrity Validation15,000+ChecksumProduction Ready

Large Data Processing

Data SizeRate (ops/sec)Use Case
1KB Data15Small files, tokens
10KB Data17Documents, configs
100KB Data17Large files, images

Security Compliance

FortifyJS adheres to industry standards:

  • NIST SP 800-57: Key management recommendations
  • FIPS 140-2: Cryptographic module standards
  • Common Criteria: Security evaluation standards
  • OWASP: Web application security guidelines
  • SOC 2: Security and availability standards

Advanced Usage

Hybrid Encryption Strategy

import { getEncryptionSuggestion } from "fortify2-js";

const suggestion = getEncryptionSuggestion(1024);
if (suggestion.approach === "hybrid") {
    console.log(suggestion.reason);
    console.log(
        "Performance Gain:",
        suggestion.details?.estimatedPerformanceGain
    );
}

Security Monitoring

import { FortifyJS } from "fortify2-js";

const securityStatus = FortifyJS.verifyRuntimeSecurity();
if (!securityStatus.isSecure) {
    console.warn("Security threats detected:", securityStatus.threats);
}

API Documentation

SecureRandom Methods

  • getRandomBytes(length, options?): Generates secure random bytes (same as SecureRandom or Random .getRandomBytes method)
  • generateSecureToken(length, options?): Creates secure tokens
  • generateSecureUUID(options?): Produces secure UUIDs
  • createEnhancedUint8Array(bytes): Creates enhanced byte arrays

RSA Calculator Methods

  • calculateRSAKeySize(dataSize, hashAlgorithm?, allowCustomSize?): Determines optimal key size
  • generateRSAKeyPairForData(dataSize, hashAlgorithm?, allowCustomSize?): Generates optimized key pairs
  • validateDataSizeForRSAKey(dataSize, rsaKeySize, hashAlgorithm?): Validates data/key compatibility
  • getRSARecommendations(dataSize, hashAlgorithm?): Provides security recommendations
  • assessRSASecurity(keySize, hashAlgorithm, dataSize): Performs security assessment

SecureBuffer Methods

  • new SecureBuffer(size, fill?, options?): Creates a secure buffer
  • lock() / unlock(): Manages buffer access
  • verifyIntegrity(): Checks buffer integrity
  • getSecurityInfo(): Retrieves security statistics
  • clone() / resize(newSize): Performs buffer operations

📚 Documentation

Complete Documentation

  • Quick Start Guide - Get started in 5 minutes
  • SecureArray Documentation - Complete feature guide
  • API Reference - Full API documentation
  • Changelog - Latest updates and features

Security & Performance

Contributing

Contributions are welcome. Please refer to the Contributing Guide for details.

License

MIT License - see LICENSE for details.

Developed by NEHONIX | Securing the digital world with advanced cryptography

Keywords

javascript

FAQs

Package last updated on 11 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts