xypriss 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +187 -84
- package/dist/cjs/ServerFactory.js +1 -1
- package/dist/cjs/cache/SecureCacheAdapter.js +2 -2
- package/dist/cjs/cluster/cluster-manager.js +1 -1
- package/dist/cjs/cluster/index.js +30 -30
- package/dist/cjs/cluster/modules/AutoScaler.js +2 -2
- package/dist/cjs/cluster/modules/ClusterPersistenceManager.js +3 -3
- package/dist/cjs/cluster/modules/HealthMonitor.js +2 -2
- package/dist/cjs/cluster/modules/IPCManager.js +2 -2
- package/dist/cjs/cluster/modules/MetricsCollector.js +1 -1
- package/dist/cjs/cluster/modules/WorkerManager.js +2 -2
- package/dist/cjs/encryption/EncryptionService.js +12 -12
- package/dist/cjs/encryption/EncryptionService.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/middleware/safe-json-middleware.js +1 -1
- package/dist/cjs/mods/security/src/algorithms/hash-algorithms.js +727 -0
- package/dist/cjs/mods/security/src/algorithms/hash-algorithms.js.map +1 -0
- package/dist/cjs/mods/security/src/algorithms/registry.js +83 -0
- package/dist/cjs/mods/security/src/algorithms/registry.js.map +1 -0
- package/dist/cjs/mods/security/src/components/attestation.js +1065 -0
- package/dist/cjs/mods/security/src/components/attestation.js.map +1 -0
- package/dist/cjs/mods/security/src/components/cache/FastLRU.js +323 -0
- package/dist/cjs/mods/security/src/components/cache/FastLRU.js.map +1 -0
- package/dist/cjs/mods/security/src/components/cache/UFSIMC.js +1131 -0
- package/dist/cjs/mods/security/src/components/cache/UFSIMC.js.map +1 -0
- package/dist/cjs/mods/security/src/components/cache/cacheSys.js +624 -0
- package/dist/cjs/mods/security/src/components/cache/cacheSys.js.map +1 -0
- package/dist/cjs/mods/security/src/components/cache/cacheSys.utils.js +136 -0
- package/dist/cjs/mods/security/src/components/cache/cacheSys.utils.js.map +1 -0
- package/dist/cjs/mods/security/src/components/cache/config/cache.config.js +39 -0
- package/dist/cjs/mods/security/src/components/cache/config/cache.config.js.map +1 -0
- package/dist/cjs/mods/security/src/components/cache/index.js +459 -0
- package/dist/cjs/mods/security/src/components/cache/index.js.map +1 -0
- package/dist/cjs/mods/security/src/components/cache/useCache.js +243 -0
- package/dist/cjs/mods/security/src/components/cache/useCache.js.map +1 -0
- package/dist/cjs/mods/security/src/components/canary-tokens.js +351 -0
- package/dist/cjs/mods/security/src/components/canary-tokens.js.map +1 -0
- package/dist/cjs/mods/security/src/components/entropy-augmentation.js +478 -0
- package/dist/cjs/mods/security/src/components/entropy-augmentation.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js +338 -0
- package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js +536 -0
- package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js +631 -0
- package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/const/exec.const.js +18 -0
- package/dist/cjs/mods/security/src/components/fortified-function/const/exec.const.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-config.js +356 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-config.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-function-core.js +520 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-function-core.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-logger.js +246 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-logger.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/api-manager.js +189 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/api-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/cache-manager.js +107 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/cache-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-context.js +105 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-context.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-engine.js +127 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-engine.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-router.js +93 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-router.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/memory-manager.js +147 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/memory-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/security-manager.js +102 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/security-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/stats-manager.js +159 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/stats-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/timing-manager.js +125 -0
- package/dist/cjs/mods/security/src/components/fortified-function/core/mods/timing-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/engines/analytics-engine.js +370 -0
- package/dist/cjs/mods/security/src/components/fortified-function/engines/analytics-engine.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/engines/execution-engine.js +402 -0
- package/dist/cjs/mods/security/src/components/fortified-function/engines/execution-engine.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/index.js +172 -0
- package/dist/cjs/mods/security/src/components/fortified-function/index.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-monitor.js +240 -0
- package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-monitor.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-timer.js +188 -0
- package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-timer.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/security/security-handler.js +253 -0
- package/dist/cjs/mods/security/src/components/fortified-function/security/security-handler.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/serializer/safe-serializer.js +350 -0
- package/dist/cjs/mods/security/src/components/fortified-function/serializer/safe-serializer.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/smart-cache.js +693 -0
- package/dist/cjs/mods/security/src/components/fortified-function/smart-cache.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/types/types.js +16 -0
- package/dist/cjs/mods/security/src/components/fortified-function/types/types.js.map +1 -0
- package/dist/cjs/mods/security/src/components/fortified-function/utils/utils.js +68 -0
- package/dist/cjs/mods/security/src/components/fortified-function/utils/utils.js.map +1 -0
- package/dist/cjs/mods/security/src/components/memory-hard.js +922 -0
- package/dist/cjs/mods/security/src/components/memory-hard.js.map +1 -0
- package/dist/cjs/mods/security/src/components/post-quantum.js +323 -0
- package/dist/cjs/mods/security/src/components/post-quantum.js.map +1 -0
- package/dist/cjs/mods/security/src/components/runtime-verification.js +645 -0
- package/dist/cjs/mods/security/src/components/runtime-verification.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/core/secure-array-core.js +1572 -0
- package/dist/cjs/mods/security/src/components/secure-array/core/secure-array-core.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js +330 -0
- package/dist/cjs/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/events/event-manager.js +270 -0
- package/dist/cjs/mods/security/src/components/secure-array/events/event-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/index.js +66 -0
- package/dist/cjs/mods/security/src/components/secure-array/index.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/metadata/metadata-manager.js +331 -0
- package/dist/cjs/mods/security/src/components/secure-array/metadata/metadata-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js +390 -0
- package/dist/cjs/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/types/index.js +87 -0
- package/dist/cjs/mods/security/src/components/secure-array/types/index.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/utils/id-generator.js +80 -0
- package/dist/cjs/mods/security/src/components/secure-array/utils/id-generator.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-array/utils/validation.js +275 -0
- package/dist/cjs/mods/security/src/components/secure-array/utils/validation.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-memory.js +906 -0
- package/dist/cjs/mods/security/src/components/secure-memory.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/core/secure-object-core.js +1605 -0
- package/dist/cjs/mods/security/src/components/secure-object/core/secure-object-core.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/encryption/crypto-handler.js +362 -0
- package/dist/cjs/mods/security/src/components/secure-object/encryption/crypto-handler.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/encryption/sensitive-keys.js +206 -0
- package/dist/cjs/mods/security/src/components/secure-object/encryption/sensitive-keys.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/events/event-manager.js +197 -0
- package/dist/cjs/mods/security/src/components/secure-object/events/event-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/index.js +67 -0
- package/dist/cjs/mods/security/src/components/secure-object/index.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/metadata/metadata-manager.js +183 -0
- package/dist/cjs/mods/security/src/components/secure-object/metadata/metadata-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/serialization/serialization-handler.js +197 -0
- package/dist/cjs/mods/security/src/components/secure-object/serialization/serialization-handler.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/utils/id-generator.js +64 -0
- package/dist/cjs/mods/security/src/components/secure-object/utils/id-generator.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-object/utils/validation.js +239 -0
- package/dist/cjs/mods/security/src/components/secure-object/utils/validation.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-serialization.js +772 -0
- package/dist/cjs/mods/security/src/components/secure-serialization.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/advanced/entropy-analyzer.js +308 -0
- package/dist/cjs/mods/security/src/components/secure-string/advanced/entropy-analyzer.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/advanced/performance-monitor.js +335 -0
- package/dist/cjs/mods/security/src/components/secure-string/advanced/performance-monitor.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/advanced/quantum-safe.js +245 -0
- package/dist/cjs/mods/security/src/components/secure-string/advanced/quantum-safe.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/buffer/buffer-manager.js +205 -0
- package/dist/cjs/mods/security/src/components/secure-string/buffer/buffer-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/core/secure-string-core.js +788 -0
- package/dist/cjs/mods/security/src/components/secure-string/core/secure-string-core.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/crypto/crypto-operations.js +319 -0
- package/dist/cjs/mods/security/src/components/secure-string/crypto/crypto-operations.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/operations/comparison-operations.js +221 -0
- package/dist/cjs/mods/security/src/components/secure-string/operations/comparison-operations.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/operations/string-operations.js +234 -0
- package/dist/cjs/mods/security/src/components/secure-string/operations/string-operations.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/types/index.js +41 -0
- package/dist/cjs/mods/security/src/components/secure-string/types/index.js.map +1 -0
- package/dist/cjs/mods/security/src/components/secure-string/validation/string-validator.js +334 -0
- package/dist/cjs/mods/security/src/components/secure-string/validation/string-validator.js.map +1 -0
- package/dist/cjs/mods/security/src/components/side-channel.js +146 -0
- package/dist/cjs/mods/security/src/components/side-channel.js.map +1 -0
- package/dist/cjs/mods/security/src/components/tamper-evident-logging.js +391 -0
- package/dist/cjs/mods/security/src/components/tamper-evident-logging.js.map +1 -0
- package/dist/cjs/mods/security/src/const/buffer.const.js +15 -0
- package/dist/cjs/mods/security/src/const/buffer.const.js.map +1 -0
- package/dist/cjs/mods/security/src/core/crypto.js +722 -0
- package/dist/cjs/mods/security/src/core/crypto.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash/hash-advanced.js +388 -0
- package/dist/cjs/mods/security/src/core/hash/hash-advanced.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash/hash-core.js +376 -0
- package/dist/cjs/mods/security/src/core/hash/hash-core.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash/hash-entropy.js +307 -0
- package/dist/cjs/mods/security/src/core/hash/hash-entropy.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash/hash-security.js +372 -0
- package/dist/cjs/mods/security/src/core/hash/hash-security.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash/hash-types.js +16 -0
- package/dist/cjs/mods/security/src/core/hash/hash-types.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash/hash-utils.js +328 -0
- package/dist/cjs/mods/security/src/core/hash/hash-utils.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash/hash-validator.js +312 -0
- package/dist/cjs/mods/security/src/core/hash/hash-validator.js.map +1 -0
- package/dist/cjs/mods/security/src/core/hash.js +25 -0
- package/dist/cjs/mods/security/src/core/hash.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js +135 -0
- package/dist/cjs/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js +293 -0
- package/dist/cjs/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js +317 -0
- package/dist/cjs/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys/keys-core.js +201 -0
- package/dist/cjs/mods/security/src/core/keys/keys-core.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys/keys-logger.js +234 -0
- package/dist/cjs/mods/security/src/core/keys/keys-logger.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys/keys-types.js +65 -0
- package/dist/cjs/mods/security/src/core/keys/keys-types.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys/keys-utils.js +322 -0
- package/dist/cjs/mods/security/src/core/keys/keys-utils.js.map +1 -0
- package/dist/cjs/mods/security/src/core/keys.js +136 -0
- package/dist/cjs/mods/security/src/core/keys.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/index.js +122 -0
- package/dist/cjs/mods/security/src/core/password/index.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/password-algorithms.js +397 -0
- package/dist/cjs/mods/security/src/core/password/password-algorithms.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/password-core.js +294 -0
- package/dist/cjs/mods/security/src/core/password/password-core.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/password-generator.js +365 -0
- package/dist/cjs/mods/security/src/core/password/password-generator.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/password-migration.js +237 -0
- package/dist/cjs/mods/security/src/core/password/password-migration.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/password-security.js +534 -0
- package/dist/cjs/mods/security/src/core/password/password-security.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/password-types.js +39 -0
- package/dist/cjs/mods/security/src/core/password/password-types.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/password-utils.js +651 -0
- package/dist/cjs/mods/security/src/core/password/password-utils.js.map +1 -0
- package/dist/cjs/mods/security/src/core/password/swlist.js +1122 -0
- package/dist/cjs/mods/security/src/core/password/swlist.js.map +1 -0
- package/dist/cjs/mods/security/src/core/random/random-core.js +328 -0
- package/dist/cjs/mods/security/src/core/random/random-core.js.map +1 -0
- package/dist/cjs/mods/security/src/core/random/random-crypto.js +339 -0
- package/dist/cjs/mods/security/src/core/random/random-crypto.js.map +1 -0
- package/dist/cjs/mods/security/src/core/random/random-entropy.js +388 -0
- package/dist/cjs/mods/security/src/core/random/random-entropy.js.map +1 -0
- package/dist/cjs/mods/security/src/core/random/random-generators.js +344 -0
- package/dist/cjs/mods/security/src/core/random/random-generators.js.map +1 -0
- package/dist/cjs/mods/security/src/core/random/random-sources.js +426 -0
- package/dist/cjs/mods/security/src/core/random/random-sources.js.map +1 -0
- package/dist/cjs/mods/security/src/core/random/random-tokens.js +309 -0
- package/dist/cjs/mods/security/src/core/random/random-tokens.js.map +1 -0
- package/dist/cjs/mods/security/src/core/random/random-types.js +36 -0
- package/dist/cjs/mods/security/src/core/random/random-types.js.map +1 -0
- package/dist/cjs/mods/security/src/core/validators.js +200 -0
- package/dist/cjs/mods/security/src/core/validators.js.map +1 -0
- package/dist/cjs/mods/security/src/helpers/Uint8Array.js +335 -0
- package/dist/cjs/mods/security/src/helpers/Uint8Array.js.map +1 -0
- package/dist/cjs/mods/security/src/helpers/createEnu.js +27 -0
- package/dist/cjs/mods/security/src/helpers/createEnu.js.map +1 -0
- package/dist/cjs/mods/security/src/index.js +417 -0
- package/dist/cjs/mods/security/src/index.js.map +1 -0
- package/dist/cjs/mods/security/src/types/global.js +51 -0
- package/dist/cjs/mods/security/src/types/global.js.map +1 -0
- package/dist/cjs/mods/security/src/types/secure-mem.type.js +100 -0
- package/dist/cjs/mods/security/src/types/secure-mem.type.js.map +1 -0
- package/dist/cjs/mods/security/src/types/secure-memory.js +20 -0
- package/dist/cjs/mods/security/src/types/secure-memory.js.map +1 -0
- package/dist/cjs/mods/security/src/types.js +63 -0
- package/dist/cjs/mods/security/src/types.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/CryptoAlgorithmUtils.js +71 -0
- package/dist/cjs/mods/security/src/utils/CryptoAlgorithmUtils.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/constants.js +111 -0
- package/dist/cjs/mods/security/src/utils/constants.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/dataConverter.js +74 -0
- package/dist/cjs/mods/security/src/utils/dataConverter.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/encoding.js +290 -0
- package/dist/cjs/mods/security/src/utils/encoding.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/errorHandler.js +140 -0
- package/dist/cjs/mods/security/src/utils/errorHandler.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/memory/config-manager.js +282 -0
- package/dist/cjs/mods/security/src/utils/memory/config-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/memory/event-manager.js +277 -0
- package/dist/cjs/mods/security/src/utils/memory/event-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/memory/index.js +162 -0
- package/dist/cjs/mods/security/src/utils/memory/index.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/memory/memory-manager.js +888 -0
- package/dist/cjs/mods/security/src/utils/memory/memory-manager.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/memory/memory-pool.js +356 -0
- package/dist/cjs/mods/security/src/utils/memory/memory-pool.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/memory/reference-tracker.js +376 -0
- package/dist/cjs/mods/security/src/utils/memory/reference-tracker.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/memory/types.js +56 -0
- package/dist/cjs/mods/security/src/utils/memory/types.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/patterns.js +127 -0
- package/dist/cjs/mods/security/src/utils/patterns.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/performanceMonitor.js +249 -0
- package/dist/cjs/mods/security/src/utils/performanceMonitor.js.map +1 -0
- package/dist/cjs/mods/security/src/utils/stats.js +182 -0
- package/dist/cjs/mods/security/src/utils/stats.js.map +1 -0
- package/dist/cjs/security-middleware.js +15 -15
- package/dist/cjs/server/components/fastapi/UltraFastRequestProcessor.js +1 -1
- package/dist/cjs/server/components/fastapi/console/ConsoleInterceptor.js +23 -23
- package/dist/cjs/server/components/fastapi/middlewares/MiddlewareAPI.js +1 -1
- package/dist/cjs/server/optimization/RequestPreCompiler.js +1 -1
- package/dist/cjs/server/plugins/PluginRegistry.js +1 -1
- package/dist/cjs/server/plugins/core/CachePlugin.js +7 -7
- package/dist/cjs/server/plugins/core/PerformancePlugin.js +2 -2
- package/dist/cjs/server/plugins/core/SecurityPlugin.js +10 -10
- package/dist/cjs/smart-routes.js +1 -1
- package/dist/esm/ServerFactory.js +1 -1
- package/dist/esm/cache/SecureCacheAdapter.js +2 -2
- package/dist/esm/cluster/cluster-manager.js +1 -1
- package/dist/esm/cluster/index.js +30 -30
- package/dist/esm/cluster/modules/AutoScaler.js +2 -2
- package/dist/esm/cluster/modules/ClusterPersistenceManager.js +3 -3
- package/dist/esm/cluster/modules/HealthMonitor.js +2 -2
- package/dist/esm/cluster/modules/IPCManager.js +2 -2
- package/dist/esm/cluster/modules/MetricsCollector.js +1 -1
- package/dist/esm/cluster/modules/WorkerManager.js +2 -2
- package/dist/esm/encryption/EncryptionService.js +12 -12
- package/dist/esm/encryption/EncryptionService.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/middleware/safe-json-middleware.js +1 -1
- package/dist/esm/mods/security/src/algorithms/hash-algorithms.js +705 -0
- package/dist/esm/mods/security/src/algorithms/hash-algorithms.js.map +1 -0
- package/dist/esm/mods/security/src/algorithms/registry.js +81 -0
- package/dist/esm/mods/security/src/algorithms/registry.js.map +1 -0
- package/dist/esm/mods/security/src/components/attestation.js +1059 -0
- package/dist/esm/mods/security/src/components/attestation.js.map +1 -0
- package/dist/esm/mods/security/src/components/cache/FastLRU.js +320 -0
- package/dist/esm/mods/security/src/components/cache/FastLRU.js.map +1 -0
- package/dist/esm/mods/security/src/components/cache/UFSIMC.js +1109 -0
- package/dist/esm/mods/security/src/components/cache/UFSIMC.js.map +1 -0
- package/dist/esm/mods/security/src/components/cache/cacheSys.js +622 -0
- package/dist/esm/mods/security/src/components/cache/cacheSys.js.map +1 -0
- package/dist/esm/mods/security/src/components/cache/cacheSys.utils.js +111 -0
- package/dist/esm/mods/security/src/components/cache/cacheSys.utils.js.map +1 -0
- package/dist/esm/mods/security/src/components/cache/config/cache.config.js +36 -0
- package/dist/esm/mods/security/src/components/cache/config/cache.config.js.map +1 -0
- package/dist/esm/mods/security/src/components/cache/index.js +449 -0
- package/dist/esm/mods/security/src/components/cache/index.js.map +1 -0
- package/dist/esm/mods/security/src/components/cache/useCache.js +240 -0
- package/dist/esm/mods/security/src/components/cache/useCache.js.map +1 -0
- package/dist/esm/mods/security/src/components/canary-tokens.js +346 -0
- package/dist/esm/mods/security/src/components/canary-tokens.js.map +1 -0
- package/dist/esm/mods/security/src/components/entropy-augmentation.js +476 -0
- package/dist/esm/mods/security/src/components/entropy-augmentation.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js +336 -0
- package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js +534 -0
- package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js +629 -0
- package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/const/exec.const.js +11 -0
- package/dist/esm/mods/security/src/components/fortified-function/const/exec.const.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/fortified-config.js +351 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/fortified-config.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/fortified-function-core.js +518 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/fortified-function-core.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/fortified-logger.js +243 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/fortified-logger.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/api-manager.js +187 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/api-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/cache-manager.js +105 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/cache-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-context.js +103 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-context.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-engine.js +125 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-engine.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-router.js +91 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-router.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/memory-manager.js +145 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/memory-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/security-manager.js +100 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/security-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/stats-manager.js +157 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/stats-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/timing-manager.js +123 -0
- package/dist/esm/mods/security/src/components/fortified-function/core/mods/timing-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/engines/analytics-engine.js +368 -0
- package/dist/esm/mods/security/src/components/fortified-function/engines/analytics-engine.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/engines/execution-engine.js +400 -0
- package/dist/esm/mods/security/src/components/fortified-function/engines/execution-engine.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/index.js +165 -0
- package/dist/esm/mods/security/src/components/fortified-function/index.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/performance/performance-monitor.js +238 -0
- package/dist/esm/mods/security/src/components/fortified-function/performance/performance-monitor.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/performance/performance-timer.js +186 -0
- package/dist/esm/mods/security/src/components/fortified-function/performance/performance-timer.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/security/security-handler.js +251 -0
- package/dist/esm/mods/security/src/components/fortified-function/security/security-handler.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/serializer/safe-serializer.js +344 -0
- package/dist/esm/mods/security/src/components/fortified-function/serializer/safe-serializer.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/smart-cache.js +691 -0
- package/dist/esm/mods/security/src/components/fortified-function/smart-cache.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/types/types.js +14 -0
- package/dist/esm/mods/security/src/components/fortified-function/types/types.js.map +1 -0
- package/dist/esm/mods/security/src/components/fortified-function/utils/utils.js +66 -0
- package/dist/esm/mods/security/src/components/fortified-function/utils/utils.js.map +1 -0
- package/dist/esm/mods/security/src/components/memory-hard.js +919 -0
- package/dist/esm/mods/security/src/components/memory-hard.js.map +1 -0
- package/dist/esm/mods/security/src/components/post-quantum.js +316 -0
- package/dist/esm/mods/security/src/components/post-quantum.js.map +1 -0
- package/dist/esm/mods/security/src/components/runtime-verification.js +643 -0
- package/dist/esm/mods/security/src/components/runtime-verification.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/core/secure-array-core.js +1570 -0
- package/dist/esm/mods/security/src/components/secure-array/core/secure-array-core.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js +328 -0
- package/dist/esm/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/events/event-manager.js +268 -0
- package/dist/esm/mods/security/src/components/secure-array/events/event-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/index.js +61 -0
- package/dist/esm/mods/security/src/components/secure-array/index.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/metadata/metadata-manager.js +329 -0
- package/dist/esm/mods/security/src/components/secure-array/metadata/metadata-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js +388 -0
- package/dist/esm/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/types/index.js +84 -0
- package/dist/esm/mods/security/src/components/secure-array/types/index.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/utils/id-generator.js +78 -0
- package/dist/esm/mods/security/src/components/secure-array/utils/id-generator.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-array/utils/validation.js +273 -0
- package/dist/esm/mods/security/src/components/secure-array/utils/validation.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-memory.js +884 -0
- package/dist/esm/mods/security/src/components/secure-memory.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/core/secure-object-core.js +1603 -0
- package/dist/esm/mods/security/src/components/secure-object/core/secure-object-core.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/encryption/crypto-handler.js +360 -0
- package/dist/esm/mods/security/src/components/secure-object/encryption/crypto-handler.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/encryption/sensitive-keys.js +203 -0
- package/dist/esm/mods/security/src/components/secure-object/encryption/sensitive-keys.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/events/event-manager.js +195 -0
- package/dist/esm/mods/security/src/components/secure-object/events/event-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/index.js +63 -0
- package/dist/esm/mods/security/src/components/secure-object/index.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/metadata/metadata-manager.js +181 -0
- package/dist/esm/mods/security/src/components/secure-object/metadata/metadata-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/serialization/serialization-handler.js +195 -0
- package/dist/esm/mods/security/src/components/secure-object/serialization/serialization-handler.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/utils/id-generator.js +62 -0
- package/dist/esm/mods/security/src/components/secure-object/utils/id-generator.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-object/utils/validation.js +237 -0
- package/dist/esm/mods/security/src/components/secure-object/utils/validation.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-serialization.js +769 -0
- package/dist/esm/mods/security/src/components/secure-serialization.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/advanced/entropy-analyzer.js +306 -0
- package/dist/esm/mods/security/src/components/secure-string/advanced/entropy-analyzer.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/advanced/performance-monitor.js +333 -0
- package/dist/esm/mods/security/src/components/secure-string/advanced/performance-monitor.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/advanced/quantum-safe.js +243 -0
- package/dist/esm/mods/security/src/components/secure-string/advanced/quantum-safe.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/buffer/buffer-manager.js +203 -0
- package/dist/esm/mods/security/src/components/secure-string/buffer/buffer-manager.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/core/secure-string-core.js +786 -0
- package/dist/esm/mods/security/src/components/secure-string/core/secure-string-core.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/crypto/crypto-operations.js +298 -0
- package/dist/esm/mods/security/src/components/secure-string/crypto/crypto-operations.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/operations/comparison-operations.js +219 -0
- package/dist/esm/mods/security/src/components/secure-string/operations/comparison-operations.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/operations/string-operations.js +232 -0
- package/dist/esm/mods/security/src/components/secure-string/operations/string-operations.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/types/index.js +37 -0
- package/dist/esm/mods/security/src/components/secure-string/types/index.js.map +1 -0
- package/dist/esm/mods/security/src/components/secure-string/validation/string-validator.js +332 -0
- package/dist/esm/mods/security/src/components/secure-string/validation/string-validator.js.map +1 -0
- package/dist/esm/mods/security/src/components/side-channel.js +142 -0
- package/dist/esm/mods/security/src/components/side-channel.js.map +1 -0
- package/dist/esm/mods/security/src/components/tamper-evident-logging.js +389 -0
- package/dist/esm/mods/security/src/components/tamper-evident-logging.js.map +1 -0
- package/dist/esm/mods/security/src/const/buffer.const.js +13 -0
- package/dist/esm/mods/security/src/const/buffer.const.js.map +1 -0
- package/dist/esm/mods/security/src/core/crypto.js +720 -0
- package/dist/esm/mods/security/src/core/crypto.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash/hash-advanced.js +367 -0
- package/dist/esm/mods/security/src/core/hash/hash-advanced.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash/hash-core.js +355 -0
- package/dist/esm/mods/security/src/core/hash/hash-core.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash/hash-entropy.js +286 -0
- package/dist/esm/mods/security/src/core/hash/hash-entropy.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash/hash-security.js +351 -0
- package/dist/esm/mods/security/src/core/hash/hash-security.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash/hash-types.js +16 -0
- package/dist/esm/mods/security/src/core/hash/hash-types.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash/hash-utils.js +307 -0
- package/dist/esm/mods/security/src/core/hash/hash-utils.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash/hash-validator.js +310 -0
- package/dist/esm/mods/security/src/core/hash/hash-validator.js.map +1 -0
- package/dist/esm/mods/security/src/core/hash.js +9 -0
- package/dist/esm/mods/security/src/core/hash.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js +133 -0
- package/dist/esm/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js +272 -0
- package/dist/esm/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js +296 -0
- package/dist/esm/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys/keys-core.js +199 -0
- package/dist/esm/mods/security/src/core/keys/keys-core.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys/keys-logger.js +231 -0
- package/dist/esm/mods/security/src/core/keys/keys-logger.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys/keys-types.js +63 -0
- package/dist/esm/mods/security/src/core/keys/keys-types.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys/keys-utils.js +316 -0
- package/dist/esm/mods/security/src/core/keys/keys-utils.js.map +1 -0
- package/dist/esm/mods/security/src/core/keys.js +134 -0
- package/dist/esm/mods/security/src/core/keys.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/index.js +110 -0
- package/dist/esm/mods/security/src/core/password/index.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/password-algorithms.js +395 -0
- package/dist/esm/mods/security/src/core/password/password-algorithms.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/password-core.js +292 -0
- package/dist/esm/mods/security/src/core/password/password-core.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/password-generator.js +363 -0
- package/dist/esm/mods/security/src/core/password/password-generator.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/password-migration.js +235 -0
- package/dist/esm/mods/security/src/core/password/password-migration.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/password-security.js +532 -0
- package/dist/esm/mods/security/src/core/password/password-security.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/password-types.js +34 -0
- package/dist/esm/mods/security/src/core/password/password-types.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/password-utils.js +630 -0
- package/dist/esm/mods/security/src/core/password/password-utils.js.map +1 -0
- package/dist/esm/mods/security/src/core/password/swlist.js +1120 -0
- package/dist/esm/mods/security/src/core/password/swlist.js.map +1 -0
- package/dist/esm/mods/security/src/core/random/random-core.js +326 -0
- package/dist/esm/mods/security/src/core/random/random-core.js.map +1 -0
- package/dist/esm/mods/security/src/core/random/random-crypto.js +337 -0
- package/dist/esm/mods/security/src/core/random/random-crypto.js.map +1 -0
- package/dist/esm/mods/security/src/core/random/random-entropy.js +367 -0
- package/dist/esm/mods/security/src/core/random/random-entropy.js.map +1 -0
- package/dist/esm/mods/security/src/core/random/random-generators.js +323 -0
- package/dist/esm/mods/security/src/core/random/random-generators.js.map +1 -0
- package/dist/esm/mods/security/src/core/random/random-sources.js +405 -0
- package/dist/esm/mods/security/src/core/random/random-sources.js.map +1 -0
- package/dist/esm/mods/security/src/core/random/random-tokens.js +307 -0
- package/dist/esm/mods/security/src/core/random/random-tokens.js.map +1 -0
- package/dist/esm/mods/security/src/core/random/random-types.js +27 -0
- package/dist/esm/mods/security/src/core/random/random-types.js.map +1 -0
- package/dist/esm/mods/security/src/core/validators.js +198 -0
- package/dist/esm/mods/security/src/core/validators.js.map +1 -0
- package/dist/esm/mods/security/src/helpers/Uint8Array.js +333 -0
- package/dist/esm/mods/security/src/helpers/Uint8Array.js.map +1 -0
- package/dist/esm/mods/security/src/helpers/createEnu.js +25 -0
- package/dist/esm/mods/security/src/helpers/createEnu.js.map +1 -0
- package/dist/esm/mods/security/src/index.js +373 -0
- package/dist/esm/mods/security/src/index.js.map +1 -0
- package/dist/esm/mods/security/src/types/global.js +49 -0
- package/dist/esm/mods/security/src/types/global.js.map +1 -0
- package/dist/esm/mods/security/src/types/secure-mem.type.js +96 -0
- package/dist/esm/mods/security/src/types/secure-mem.type.js.map +1 -0
- package/dist/esm/mods/security/src/types/secure-memory.js +20 -0
- package/dist/esm/mods/security/src/types/secure-memory.js.map +1 -0
- package/dist/esm/mods/security/src/types.js +63 -0
- package/dist/esm/mods/security/src/types.js.map +1 -0
- package/dist/esm/mods/security/src/utils/CryptoAlgorithmUtils.js +69 -0
- package/dist/esm/mods/security/src/utils/CryptoAlgorithmUtils.js.map +1 -0
- package/dist/esm/mods/security/src/utils/constants.js +105 -0
- package/dist/esm/mods/security/src/utils/constants.js.map +1 -0
- package/dist/esm/mods/security/src/utils/dataConverter.js +72 -0
- package/dist/esm/mods/security/src/utils/dataConverter.js.map +1 -0
- package/dist/esm/mods/security/src/utils/encoding.js +279 -0
- package/dist/esm/mods/security/src/utils/encoding.js.map +1 -0
- package/dist/esm/mods/security/src/utils/errorHandler.js +137 -0
- package/dist/esm/mods/security/src/utils/errorHandler.js.map +1 -0
- package/dist/esm/mods/security/src/utils/memory/config-manager.js +280 -0
- package/dist/esm/mods/security/src/utils/memory/config-manager.js.map +1 -0
- package/dist/esm/mods/security/src/utils/memory/event-manager.js +275 -0
- package/dist/esm/mods/security/src/utils/memory/event-manager.js.map +1 -0
- package/dist/esm/mods/security/src/utils/memory/index.js +141 -0
- package/dist/esm/mods/security/src/utils/memory/index.js.map +1 -0
- package/dist/esm/mods/security/src/utils/memory/memory-manager.js +886 -0
- package/dist/esm/mods/security/src/utils/memory/memory-manager.js.map +1 -0
- package/dist/esm/mods/security/src/utils/memory/memory-pool.js +354 -0
- package/dist/esm/mods/security/src/utils/memory/memory-pool.js.map +1 -0
- package/dist/esm/mods/security/src/utils/memory/reference-tracker.js +374 -0
- package/dist/esm/mods/security/src/utils/memory/reference-tracker.js.map +1 -0
- package/dist/esm/mods/security/src/utils/memory/types.js +56 -0
- package/dist/esm/mods/security/src/utils/memory/types.js.map +1 -0
- package/dist/esm/mods/security/src/utils/patterns.js +124 -0
- package/dist/esm/mods/security/src/utils/patterns.js.map +1 -0
- package/dist/esm/mods/security/src/utils/performanceMonitor.js +246 -0
- package/dist/esm/mods/security/src/utils/performanceMonitor.js.map +1 -0
- package/dist/esm/mods/security/src/utils/stats.js +180 -0
- package/dist/esm/mods/security/src/utils/stats.js.map +1 -0
- package/dist/esm/security-middleware.js +15 -15
- package/dist/esm/server/components/fastapi/UltraFastRequestProcessor.js +1 -1
- package/dist/esm/server/components/fastapi/console/ConsoleInterceptor.js +23 -23
- package/dist/esm/server/components/fastapi/middlewares/MiddlewareAPI.js +1 -1
- package/dist/esm/server/optimization/RequestPreCompiler.js +1 -1
- package/dist/esm/server/plugins/PluginRegistry.js +1 -1
- package/dist/esm/server/plugins/core/CachePlugin.js +7 -7
- package/dist/esm/server/plugins/core/PerformancePlugin.js +2 -2
- package/dist/esm/server/plugins/core/SecurityPlugin.js +10 -10
- package/dist/esm/smart-routes.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,1603 @@
|
|
|
1
|
+
import { SecureBuffer } from '../../secure-memory.js';
|
|
2
|
+
import { memoryManager, MemoryUtils } from '../../../utils/memory/index.js';
|
|
3
|
+
import { SensitiveKeysManager } from '../encryption/sensitive-keys.js';
|
|
4
|
+
import { CryptoHandler } from '../encryption/crypto-handler.js';
|
|
5
|
+
import { MetadataManager } from '../metadata/metadata-manager.js';
|
|
6
|
+
import { EventManager } from '../events/event-manager.js';
|
|
7
|
+
import { SerializationHandler } from '../serialization/serialization-handler.js';
|
|
8
|
+
import { IdGenerator } from '../utils/id-generator.js';
|
|
9
|
+
import { ValidationUtils } from '../utils/validation.js';
|
|
10
|
+
import { SecureString } from '../../secure-string/core/secure-string-core.js';
|
|
11
|
+
import 'crypto';
|
|
12
|
+
import '../../secure-string/advanced/entropy-analyzer.js';
|
|
13
|
+
import '../../secure-string/advanced/quantum-safe.js';
|
|
14
|
+
import '../../secure-string/advanced/performance-monitor.js';
|
|
15
|
+
import { MemoryEventType, PoolStrategy } from '../../../utils/memory/types.js';
|
|
16
|
+
|
|
17
|
+
/***************************************************************************
|
|
18
|
+
* XyPrissSecurity - Secure Array Types
|
|
19
|
+
*
|
|
20
|
+
* This file contains type definitions for the SecureArray modular architecture
|
|
21
|
+
*
|
|
22
|
+
* @author Nehonix
|
|
23
|
+
*
|
|
24
|
+
* @license MIT
|
|
25
|
+
*
|
|
26
|
+
* Copyright (c) 2025 Nehonix. All rights reserved.
|
|
27
|
+
*
|
|
28
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
29
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
30
|
+
* in the Software without restriction, including without limitation the rights
|
|
31
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
32
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
33
|
+
* furnished to do so, subject to the following conditions:
|
|
34
|
+
*
|
|
35
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
36
|
+
* copies or substantial portions of the Software.
|
|
37
|
+
*
|
|
38
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
39
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
40
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
41
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
42
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
43
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
44
|
+
* SOFTWARE.
|
|
45
|
+
***************************************************************************** */
|
|
46
|
+
/**
|
|
47
|
+
* A secure object that can store sensitive data
|
|
48
|
+
* T represents the initial type, but the object can be extended with additional keys
|
|
49
|
+
*/
|
|
50
|
+
class SecureObject {
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new secure object
|
|
53
|
+
*/
|
|
54
|
+
constructor(initialData, options) {
|
|
55
|
+
// Core data storage
|
|
56
|
+
this.data = new Map();
|
|
57
|
+
this.secureBuffers = new Map();
|
|
58
|
+
// State management
|
|
59
|
+
this._isDestroyed = false;
|
|
60
|
+
this._isReadOnly = false;
|
|
61
|
+
// Enhanced memory management
|
|
62
|
+
this._memoryTracking = false;
|
|
63
|
+
this._autoCleanup = false;
|
|
64
|
+
this._createdAt = Date.now();
|
|
65
|
+
this._lastAccessed = Date.now();
|
|
66
|
+
this._id = IdGenerator.generate();
|
|
67
|
+
this._isReadOnly = false; // Start as writable
|
|
68
|
+
// Initialize modular components
|
|
69
|
+
this.sensitiveKeysManager = new SensitiveKeysManager();
|
|
70
|
+
this.cryptoHandler = new CryptoHandler(this._id);
|
|
71
|
+
this.metadataManager = new MetadataManager();
|
|
72
|
+
this.eventManager = new EventManager();
|
|
73
|
+
this.serializationHandler = new SerializationHandler(this.cryptoHandler, this.metadataManager);
|
|
74
|
+
// Set encryption key if provided
|
|
75
|
+
if (options?.encryptionKey) {
|
|
76
|
+
this.cryptoHandler.setEncryptionKey(options.encryptionKey);
|
|
77
|
+
}
|
|
78
|
+
// Configure memory management with enhanced features
|
|
79
|
+
this._memoryTracking = options?.enableMemoryTracking ?? true; // Enable by default
|
|
80
|
+
this._autoCleanup = options?.autoCleanup ?? true; // Enable by default
|
|
81
|
+
// Set memory limits if provided
|
|
82
|
+
if (options?.maxMemory) {
|
|
83
|
+
memoryManager.setLimits(options.maxMemory, options.gcThreshold || 0.8);
|
|
84
|
+
}
|
|
85
|
+
// Register with advanced memory manager if tracking is enabled
|
|
86
|
+
if (this._memoryTracking) {
|
|
87
|
+
memoryManager.registerObject(this, this._id);
|
|
88
|
+
// Listen to memory events for proactive management
|
|
89
|
+
memoryManager.on(MemoryEventType.MEMORY_PRESSURE, (event) => {
|
|
90
|
+
if (event.data?.pressure > 0.8) {
|
|
91
|
+
this.handleMemoryPressure();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
memoryManager.on(MemoryEventType.LEAK_DETECTED, (event) => {
|
|
95
|
+
if (event.data?.leaks?.includes(this._id)) {
|
|
96
|
+
console.warn(`Potential memory leak detected in SecureObject ${this._id}`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// Create memory pool for secure buffers if not exists
|
|
101
|
+
this.initializeSecureBufferPool();
|
|
102
|
+
// Set initial data
|
|
103
|
+
if (initialData) {
|
|
104
|
+
this.setAll(initialData);
|
|
105
|
+
}
|
|
106
|
+
// Set read-only status after initial data is set
|
|
107
|
+
this._isReadOnly = options?.readOnly ?? false;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates a SecureObject from another SecureObject (deep copy)
|
|
111
|
+
*/
|
|
112
|
+
static from(other) {
|
|
113
|
+
other.ensureNotDestroyed();
|
|
114
|
+
const copy = new SecureObject();
|
|
115
|
+
for (const key of other.keys()) {
|
|
116
|
+
const value = other.get(key);
|
|
117
|
+
copy.set(String(key), value);
|
|
118
|
+
}
|
|
119
|
+
return copy;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Creates a read-only SecureObject
|
|
123
|
+
*/
|
|
124
|
+
static readOnly(data) {
|
|
125
|
+
return new SecureObject(data, { readOnly: true });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Creates a read-only SecureObject (public usage)
|
|
129
|
+
*/
|
|
130
|
+
/** Permanently enable read-only mode (cannot be disabled). */
|
|
131
|
+
enableReadOnly() {
|
|
132
|
+
this.ensureNotDestroyed();
|
|
133
|
+
this._isReadOnly = true;
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
// ===== PROPERTY ACCESSORS =====
|
|
137
|
+
/**
|
|
138
|
+
* Gets the unique ID of this SecureObject
|
|
139
|
+
*/
|
|
140
|
+
get id() {
|
|
141
|
+
return this._id;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Checks if the SecureObject is read-only
|
|
145
|
+
*/
|
|
146
|
+
get isReadOnly() {
|
|
147
|
+
return this._isReadOnly;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Checks if the SecureObject has been destroyed
|
|
151
|
+
*/
|
|
152
|
+
get isDestroyed() {
|
|
153
|
+
return this._isDestroyed;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Gets the number of stored values
|
|
157
|
+
*/
|
|
158
|
+
get size() {
|
|
159
|
+
this.ensureNotDestroyed();
|
|
160
|
+
return this.data.size;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if the object is empty
|
|
164
|
+
*/
|
|
165
|
+
get isEmpty() {
|
|
166
|
+
this.ensureNotDestroyed();
|
|
167
|
+
return this.data.size === 0;
|
|
168
|
+
}
|
|
169
|
+
// ===== VALIDATION METHODS =====
|
|
170
|
+
/**
|
|
171
|
+
* Ensures the SecureObject hasn't been destroyed
|
|
172
|
+
*/
|
|
173
|
+
ensureNotDestroyed() {
|
|
174
|
+
if (this._isDestroyed) {
|
|
175
|
+
throw new Error("SecureObject has been destroyed and cannot be used");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Ensures the SecureObject is not read-only for write operations
|
|
180
|
+
*/
|
|
181
|
+
ensureNotReadOnly() {
|
|
182
|
+
if (this._isReadOnly) {
|
|
183
|
+
throw new Error("SecureObject is read-only");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Updates the last accessed timestamp for memory management
|
|
188
|
+
*/
|
|
189
|
+
updateLastAccessed() {
|
|
190
|
+
this._lastAccessed = Date.now();
|
|
191
|
+
}
|
|
192
|
+
// ===== MEMORY MANAGEMENT =====
|
|
193
|
+
/**
|
|
194
|
+
* Initialize secure buffer pool for efficient memory reuse
|
|
195
|
+
*/
|
|
196
|
+
initializeSecureBufferPool() {
|
|
197
|
+
if (!this.secureBufferPool) {
|
|
198
|
+
try {
|
|
199
|
+
this.secureBufferPool =
|
|
200
|
+
memoryManager.getPool("secure-buffer-pool") ||
|
|
201
|
+
memoryManager.createPool({
|
|
202
|
+
name: "secure-buffer-pool",
|
|
203
|
+
factory: () => new Uint8Array(1024), // 1KB buffers
|
|
204
|
+
reset: (buffer) => {
|
|
205
|
+
// Secure wipe before reuse
|
|
206
|
+
this.secureWipe(buffer);
|
|
207
|
+
},
|
|
208
|
+
capacity: 50,
|
|
209
|
+
strategy: PoolStrategy.LRU,
|
|
210
|
+
validator: (buffer) => buffer instanceof Uint8Array,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
// Pool might already exist, try to get it
|
|
215
|
+
this.secureBufferPool =
|
|
216
|
+
memoryManager.getPool("secure-buffer-pool");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Handle memory pressure situations
|
|
222
|
+
*/
|
|
223
|
+
handleMemoryPressure() {
|
|
224
|
+
if (this._autoCleanup) {
|
|
225
|
+
// Clean up unused secure buffers
|
|
226
|
+
this.forceGarbageCollection();
|
|
227
|
+
// Emit event for external handlers
|
|
228
|
+
this.eventManager.emit("gc", undefined, {
|
|
229
|
+
timestamp: Date.now(),
|
|
230
|
+
objectId: this._id,
|
|
231
|
+
action: "memory_pressure_cleanup",
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Secure wipe of buffer memory
|
|
237
|
+
*/
|
|
238
|
+
secureWipe(buffer) {
|
|
239
|
+
if (!buffer || buffer.length === 0)
|
|
240
|
+
return;
|
|
241
|
+
// Multiple-pass secure wipe
|
|
242
|
+
const passes = [0x00, 0xff, 0xaa, 0x55, 0x00];
|
|
243
|
+
for (const pattern of passes) {
|
|
244
|
+
buffer.fill(pattern);
|
|
245
|
+
}
|
|
246
|
+
// Final random pass if crypto is available
|
|
247
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
248
|
+
crypto.getRandomValues(buffer);
|
|
249
|
+
}
|
|
250
|
+
buffer.fill(0x00); // Final zero pass
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Gets enhanced memory usage statistics for this SecureObject
|
|
254
|
+
*/
|
|
255
|
+
getMemoryUsage() {
|
|
256
|
+
this.ensureNotDestroyed();
|
|
257
|
+
let allocatedMemory = 0;
|
|
258
|
+
for (const buffer of this.secureBuffers.values()) {
|
|
259
|
+
allocatedMemory += buffer.length();
|
|
260
|
+
}
|
|
261
|
+
const now = Date.now();
|
|
262
|
+
const usage = {
|
|
263
|
+
allocatedMemory,
|
|
264
|
+
bufferCount: this.secureBuffers.size,
|
|
265
|
+
dataSize: this.data.size,
|
|
266
|
+
createdAt: this._createdAt,
|
|
267
|
+
lastAccessed: this._lastAccessed,
|
|
268
|
+
age: now - this._createdAt,
|
|
269
|
+
formattedMemory: MemoryUtils.formatBytes(allocatedMemory),
|
|
270
|
+
poolStats: this.secureBufferPool?.getStats(),
|
|
271
|
+
};
|
|
272
|
+
return usage;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Forces enhanced garbage collection for this SecureObject
|
|
276
|
+
*/
|
|
277
|
+
forceGarbageCollection() {
|
|
278
|
+
this.ensureNotDestroyed();
|
|
279
|
+
if (this._memoryTracking) {
|
|
280
|
+
const beforeUsage = this.getMemoryUsage();
|
|
281
|
+
// Clean up unused secure buffers with secure wipe
|
|
282
|
+
for (const [key, buffer] of this.secureBuffers.entries()) {
|
|
283
|
+
if (!this.data.has(key)) {
|
|
284
|
+
// Secure wipe before destroying (get buffer data safely)
|
|
285
|
+
try {
|
|
286
|
+
const bufferData = buffer.getBuffer(); // Use correct method
|
|
287
|
+
if (bufferData instanceof Uint8Array) {
|
|
288
|
+
this.secureWipe(bufferData);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
// Buffer might already be destroyed, continue
|
|
293
|
+
}
|
|
294
|
+
buffer.destroy();
|
|
295
|
+
this.secureBuffers.delete(key);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// Return unused buffers to pool
|
|
299
|
+
if (this.secureBufferPool) ;
|
|
300
|
+
// Trigger global GC with enhanced features
|
|
301
|
+
const gcResult = memoryManager.forceGC();
|
|
302
|
+
const afterUsage = this.getMemoryUsage();
|
|
303
|
+
const freedMemory = beforeUsage.allocatedMemory - afterUsage.allocatedMemory;
|
|
304
|
+
this.eventManager.emit("gc", undefined, {
|
|
305
|
+
timestamp: Date.now(),
|
|
306
|
+
bufferCount: this.secureBuffers.size,
|
|
307
|
+
freedMemory,
|
|
308
|
+
gcDuration: gcResult.duration,
|
|
309
|
+
gcSuccess: gcResult.success,
|
|
310
|
+
beforeUsage: beforeUsage.formattedMemory,
|
|
311
|
+
afterUsage: afterUsage.formattedMemory,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Enables memory tracking for this SecureObject
|
|
317
|
+
*/
|
|
318
|
+
enableMemoryTracking() {
|
|
319
|
+
this.ensureNotDestroyed();
|
|
320
|
+
if (!this._memoryTracking) {
|
|
321
|
+
this._memoryTracking = true;
|
|
322
|
+
memoryManager.registerObject(this, this._id);
|
|
323
|
+
}
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Disables memory tracking for this SecureObject
|
|
328
|
+
*/
|
|
329
|
+
disableMemoryTracking() {
|
|
330
|
+
this.ensureNotDestroyed();
|
|
331
|
+
if (this._memoryTracking) {
|
|
332
|
+
this._memoryTracking = false;
|
|
333
|
+
memoryManager.removeReference(this._id);
|
|
334
|
+
}
|
|
335
|
+
return this;
|
|
336
|
+
}
|
|
337
|
+
// ===== SENSITIVE KEYS MANAGEMENT =====
|
|
338
|
+
/**
|
|
339
|
+
* Adds keys to the sensitive keys list
|
|
340
|
+
*/
|
|
341
|
+
addSensitiveKeys(...keys) {
|
|
342
|
+
this.ensureNotDestroyed();
|
|
343
|
+
ValidationUtils.validateKeys(keys);
|
|
344
|
+
this.sensitiveKeysManager.add(...keys);
|
|
345
|
+
return this;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Removes keys from the sensitive keys list
|
|
349
|
+
*/
|
|
350
|
+
removeSensitiveKeys(...keys) {
|
|
351
|
+
this.ensureNotDestroyed();
|
|
352
|
+
ValidationUtils.validateKeys(keys);
|
|
353
|
+
this.sensitiveKeysManager.remove(...keys);
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Sets the complete list of sensitive keys (replaces existing list)
|
|
358
|
+
*/
|
|
359
|
+
setSensitiveKeys(keys) {
|
|
360
|
+
this.ensureNotDestroyed();
|
|
361
|
+
ValidationUtils.validateKeys(keys);
|
|
362
|
+
this.sensitiveKeysManager.set(keys);
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Gets the current list of sensitive keys
|
|
367
|
+
*/
|
|
368
|
+
getSensitiveKeys() {
|
|
369
|
+
this.ensureNotDestroyed();
|
|
370
|
+
return this.sensitiveKeysManager.getAll();
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Checks if a key is marked as sensitive
|
|
374
|
+
*/
|
|
375
|
+
isSensitiveKey(key) {
|
|
376
|
+
ValidationUtils.validateKey(key);
|
|
377
|
+
return this.sensitiveKeysManager.isSensitive(key);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Clears all sensitive keys
|
|
381
|
+
*/
|
|
382
|
+
clearSensitiveKeys() {
|
|
383
|
+
this.ensureNotDestroyed();
|
|
384
|
+
this.sensitiveKeysManager.clear();
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Resets sensitive keys to default values
|
|
389
|
+
*/
|
|
390
|
+
resetToDefaultSensitiveKeys() {
|
|
391
|
+
this.ensureNotDestroyed();
|
|
392
|
+
this.sensitiveKeysManager.resetToDefault();
|
|
393
|
+
return this;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Gets the default sensitive keys that are automatically initialized
|
|
397
|
+
*/
|
|
398
|
+
static get getDefaultSensitiveKeys() {
|
|
399
|
+
return SensitiveKeysManager.getDefaultKeys();
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Adds custom regex patterns for sensitive key detection
|
|
403
|
+
* @param patterns - Regex patterns or strings to match sensitive keys
|
|
404
|
+
*/
|
|
405
|
+
addSensitivePatterns(...patterns) {
|
|
406
|
+
this.ensureNotDestroyed();
|
|
407
|
+
this.sensitiveKeysManager.addCustomPatterns(...patterns);
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Removes custom sensitive patterns
|
|
412
|
+
*/
|
|
413
|
+
removeSensitivePatterns(...patterns) {
|
|
414
|
+
this.ensureNotDestroyed();
|
|
415
|
+
this.sensitiveKeysManager.removeCustomPatterns(...patterns);
|
|
416
|
+
return this;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Clears all custom sensitive patterns
|
|
420
|
+
*/
|
|
421
|
+
clearSensitivePatterns() {
|
|
422
|
+
this.ensureNotDestroyed();
|
|
423
|
+
this.sensitiveKeysManager.clearCustomPatterns();
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Gets all custom sensitive patterns
|
|
428
|
+
*/
|
|
429
|
+
getSensitivePatterns() {
|
|
430
|
+
this.ensureNotDestroyed();
|
|
431
|
+
return this.sensitiveKeysManager.getCustomPatterns();
|
|
432
|
+
}
|
|
433
|
+
// ===== ENCRYPTION MANAGEMENT =====
|
|
434
|
+
/**
|
|
435
|
+
* Sets the encryption key for sensitive data encryption
|
|
436
|
+
*/
|
|
437
|
+
setEncryptionKey(key = null) {
|
|
438
|
+
this.ensureNotDestroyed();
|
|
439
|
+
ValidationUtils.validateEncryptionKey(key);
|
|
440
|
+
this.cryptoHandler.setEncryptionKey(key);
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Gets the current encryption key
|
|
445
|
+
*/
|
|
446
|
+
get getEncryptionKey() {
|
|
447
|
+
return this.cryptoHandler.getEncryptionKey();
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Decrypts a value using the encryption key
|
|
451
|
+
*/
|
|
452
|
+
decryptValue(encryptedValue) {
|
|
453
|
+
this.ensureNotDestroyed();
|
|
454
|
+
return this.cryptoHandler.decryptValue(encryptedValue);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Decrypts all encrypted values in an object
|
|
458
|
+
*/
|
|
459
|
+
decryptObject(obj) {
|
|
460
|
+
this.ensureNotDestroyed();
|
|
461
|
+
return this.cryptoHandler.decryptObject(obj);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Encrypts all values in the object using AES-256-CTR-HMAC encryption
|
|
465
|
+
* with proper memory management and atomic operations
|
|
466
|
+
*/
|
|
467
|
+
encryptAll() {
|
|
468
|
+
this.ensureNotDestroyed();
|
|
469
|
+
this.ensureNotReadOnly();
|
|
470
|
+
// Check if encryption key is set
|
|
471
|
+
const encryptionStatus = this.cryptoHandler.getEncryptionStatus();
|
|
472
|
+
if (!encryptionStatus.hasEncryptionKey) {
|
|
473
|
+
throw new Error("Encryption key must be set before calling encryptAll()");
|
|
474
|
+
}
|
|
475
|
+
// Prepare temporary map for atomic operation
|
|
476
|
+
const encryptedEntries = new Map();
|
|
477
|
+
const originalMetadata = new Map();
|
|
478
|
+
const keysToProcess = [];
|
|
479
|
+
try {
|
|
480
|
+
// First pass: encrypt all values into temporary storage
|
|
481
|
+
for (const [key, value] of this.data.entries()) {
|
|
482
|
+
if (value !== undefined) {
|
|
483
|
+
// Skip already encrypted values to avoid double encryption
|
|
484
|
+
if (typeof value === "string" &&
|
|
485
|
+
this.cryptoHandler.isEncrypted(value)) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
// Store original metadata for rollback
|
|
489
|
+
if (this.metadataManager.has(key)) {
|
|
490
|
+
originalMetadata.set(key, this.metadataManager.get(key));
|
|
491
|
+
}
|
|
492
|
+
// Get the actual value to encrypt
|
|
493
|
+
let valueToEncrypt = value;
|
|
494
|
+
// If it's a SecureBuffer, convert it back to its original form
|
|
495
|
+
if (value instanceof SecureBuffer) {
|
|
496
|
+
const metadata = this.metadataManager.get(key);
|
|
497
|
+
if (metadata?.type === "string") {
|
|
498
|
+
valueToEncrypt = new TextDecoder().decode(value.getBuffer());
|
|
499
|
+
}
|
|
500
|
+
else if (metadata?.type === "Uint8Array") {
|
|
501
|
+
valueToEncrypt = new Uint8Array(value.getBuffer());
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
valueToEncrypt = new TextDecoder().decode(value.getBuffer());
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
// Encrypt the value
|
|
508
|
+
const encryptedValue = this.cryptoHandler.encryptValue(valueToEncrypt);
|
|
509
|
+
encryptedEntries.set(key, encryptedValue);
|
|
510
|
+
keysToProcess.push(key);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
// Second pass: atomically commit all changes
|
|
514
|
+
for (const key of keysToProcess) {
|
|
515
|
+
const encryptedValue = encryptedEntries.get(key);
|
|
516
|
+
const originalValue = this.data.get(key);
|
|
517
|
+
// Clean up any existing SecureBuffer for this key
|
|
518
|
+
this.cleanupKey(key);
|
|
519
|
+
// Store encrypted value
|
|
520
|
+
this.data.set(key, encryptedValue);
|
|
521
|
+
// Update metadata with correct type information
|
|
522
|
+
// Store original type in the type field using special format
|
|
523
|
+
const originalType = typeof originalValue;
|
|
524
|
+
this.metadataManager.update(key, `encrypted:${originalType}`, true);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
// Rollback: restore original state on any failure
|
|
529
|
+
for (const key of keysToProcess) {
|
|
530
|
+
if (originalMetadata.has(key)) {
|
|
531
|
+
// Restore original metadata
|
|
532
|
+
const original = originalMetadata.get(key);
|
|
533
|
+
this.metadataManager.update(key, original.type, original.isSecure);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
throw new Error(`Encryption failed: ${error.message}`);
|
|
537
|
+
}
|
|
538
|
+
this.updateLastAccessed();
|
|
539
|
+
this.eventManager.emit("set", "encrypt_all", `${keysToProcess.length}_values_encrypted`);
|
|
540
|
+
return this;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Gets the raw encrypted data without decryption (for verification)
|
|
544
|
+
*/
|
|
545
|
+
getRawEncryptedData() {
|
|
546
|
+
this.ensureNotDestroyed();
|
|
547
|
+
return new Map(this.data);
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Gets a specific key's raw encrypted form (for verification)
|
|
551
|
+
*/
|
|
552
|
+
getRawEncryptedValue(key) {
|
|
553
|
+
this.ensureNotDestroyed();
|
|
554
|
+
const stringKey = ValidationUtils.sanitizeKey(key);
|
|
555
|
+
return this.data.get(stringKey);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Gets encryption status from the crypto handler
|
|
559
|
+
*/
|
|
560
|
+
getEncryptionStatus() {
|
|
561
|
+
return this.cryptoHandler.getEncryptionStatus();
|
|
562
|
+
}
|
|
563
|
+
// ===== EVENT MANAGEMENT =====
|
|
564
|
+
/**
|
|
565
|
+
* Adds an event listener
|
|
566
|
+
*/
|
|
567
|
+
addEventListener(event, listener) {
|
|
568
|
+
ValidationUtils.validateEventType(event);
|
|
569
|
+
ValidationUtils.validateEventListener(listener);
|
|
570
|
+
this.eventManager.addEventListener(event, listener);
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Removes an event listener
|
|
574
|
+
*/
|
|
575
|
+
removeEventListener(event, listener) {
|
|
576
|
+
ValidationUtils.validateEventType(event);
|
|
577
|
+
ValidationUtils.validateEventListener(listener);
|
|
578
|
+
this.eventManager.removeEventListener(event, listener);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Creates a one-time event listener
|
|
582
|
+
*/
|
|
583
|
+
once(event, listener) {
|
|
584
|
+
ValidationUtils.validateEventType(event);
|
|
585
|
+
ValidationUtils.validateEventListener(listener);
|
|
586
|
+
this.eventManager.once(event, listener);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Waits for a specific event to be emitted
|
|
590
|
+
*/
|
|
591
|
+
waitFor(event, timeout) {
|
|
592
|
+
ValidationUtils.validateEventType(event);
|
|
593
|
+
if (timeout !== undefined) {
|
|
594
|
+
ValidationUtils.validateTimeout(timeout);
|
|
595
|
+
}
|
|
596
|
+
return this.eventManager.waitFor(event, timeout);
|
|
597
|
+
}
|
|
598
|
+
// ===== CORE DATA OPERATIONS =====
|
|
599
|
+
/**
|
|
600
|
+
* Sets a value - allows both existing keys and new dynamic keys
|
|
601
|
+
*/
|
|
602
|
+
set(key, value) {
|
|
603
|
+
this.ensureNotDestroyed();
|
|
604
|
+
this.ensureNotReadOnly();
|
|
605
|
+
this.updateLastAccessed();
|
|
606
|
+
const stringKey = ValidationUtils.sanitizeKey(key);
|
|
607
|
+
ValidationUtils.isValidSecureValue(value);
|
|
608
|
+
// Clean up any existing secure buffer for this key
|
|
609
|
+
this.cleanupKey(stringKey);
|
|
610
|
+
// Handle different types of values
|
|
611
|
+
if (value &&
|
|
612
|
+
typeof value === "object" &&
|
|
613
|
+
value.constructor.name === "Uint8Array") {
|
|
614
|
+
// Store Uint8Array in a secure buffer
|
|
615
|
+
const secureBuffer = SecureBuffer.from(value);
|
|
616
|
+
this.secureBuffers.set(stringKey, secureBuffer);
|
|
617
|
+
this.data.set(stringKey, secureBuffer);
|
|
618
|
+
this.metadataManager.update(stringKey, "Uint8Array", true);
|
|
619
|
+
}
|
|
620
|
+
else if (typeof value === "string") {
|
|
621
|
+
// Store strings in secure buffers
|
|
622
|
+
const secureBuffer = SecureBuffer.from(value);
|
|
623
|
+
this.secureBuffers.set(stringKey, secureBuffer);
|
|
624
|
+
this.data.set(stringKey, secureBuffer);
|
|
625
|
+
this.metadataManager.update(stringKey, "string", true);
|
|
626
|
+
}
|
|
627
|
+
else if (ValidationUtils.isSecureString(value)) {
|
|
628
|
+
// Store SecureString reference
|
|
629
|
+
this.data.set(stringKey, value);
|
|
630
|
+
this.metadataManager.update(stringKey, "SecureString", true);
|
|
631
|
+
}
|
|
632
|
+
else if (ValidationUtils.isSecureObject(value)) {
|
|
633
|
+
// Store SecureObject reference
|
|
634
|
+
this.data.set(stringKey, value);
|
|
635
|
+
this.metadataManager.update(stringKey, "SecureObject", true);
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
// Store other values directly (numbers, booleans, null, undefined)
|
|
639
|
+
this.data.set(stringKey, value);
|
|
640
|
+
this.metadataManager.update(stringKey, typeof value, false);
|
|
641
|
+
}
|
|
642
|
+
this.eventManager.emit("set", stringKey, value);
|
|
643
|
+
return this;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Sets multiple values at once
|
|
647
|
+
*/
|
|
648
|
+
setAll(values) {
|
|
649
|
+
this.ensureNotDestroyed();
|
|
650
|
+
this.ensureNotReadOnly();
|
|
651
|
+
for (const key in values) {
|
|
652
|
+
if (Object.prototype.hasOwnProperty.call(values, key)) {
|
|
653
|
+
this.set(String(key), values[key]);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return this;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Gets a value with automatic decryption
|
|
660
|
+
*/
|
|
661
|
+
get(key) {
|
|
662
|
+
this.ensureNotDestroyed();
|
|
663
|
+
this.updateLastAccessed();
|
|
664
|
+
const stringKey = ValidationUtils.sanitizeKey(key);
|
|
665
|
+
const value = this.data.get(stringKey);
|
|
666
|
+
// Update access metadata
|
|
667
|
+
if (this.metadataManager.has(stringKey)) {
|
|
668
|
+
const metadata = this.metadataManager.get(stringKey);
|
|
669
|
+
this.metadataManager.update(stringKey, metadata.type, metadata.isSecure);
|
|
670
|
+
}
|
|
671
|
+
// Check if value is encrypted (starts with [ENCRYPTED:)
|
|
672
|
+
if (typeof value === "string" &&
|
|
673
|
+
this.cryptoHandler.isEncrypted(value)) {
|
|
674
|
+
try {
|
|
675
|
+
// Decrypt the value automatically
|
|
676
|
+
const decryptedValue = this.cryptoHandler.decryptValue(value);
|
|
677
|
+
this.eventManager.emit("get", stringKey, decryptedValue);
|
|
678
|
+
return decryptedValue;
|
|
679
|
+
}
|
|
680
|
+
catch (error) {
|
|
681
|
+
console.error(`Failed to decrypt value for key ${stringKey}:`, error);
|
|
682
|
+
// Return the encrypted value if decryption fails
|
|
683
|
+
this.eventManager.emit("get", stringKey, value);
|
|
684
|
+
return value;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (value instanceof SecureBuffer) {
|
|
688
|
+
// Convert SecureBuffer back to original type based on metadata
|
|
689
|
+
const buffer = value.getBuffer();
|
|
690
|
+
const metadata = this.metadataManager.get(stringKey);
|
|
691
|
+
if (metadata?.type === "Uint8Array" ||
|
|
692
|
+
metadata?.type === "encrypted:Uint8Array") {
|
|
693
|
+
// Return as Uint8Array for binary data
|
|
694
|
+
const result = new Uint8Array(buffer);
|
|
695
|
+
this.eventManager.emit("get", stringKey, result);
|
|
696
|
+
return result;
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
// Return as string for text data
|
|
700
|
+
const result = new TextDecoder().decode(buffer);
|
|
701
|
+
this.eventManager.emit("get", stringKey, result);
|
|
702
|
+
return result;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
this.eventManager.emit("get", stringKey, value);
|
|
706
|
+
return value;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Gets a value safely, returning undefined if key doesn't exist
|
|
710
|
+
*/
|
|
711
|
+
getSafe(key) {
|
|
712
|
+
try {
|
|
713
|
+
return this.has(key) ? this.get(key) : undefined;
|
|
714
|
+
}
|
|
715
|
+
catch {
|
|
716
|
+
return undefined;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Gets a value with a default fallback
|
|
721
|
+
*/
|
|
722
|
+
getWithDefault(key, defaultValue) {
|
|
723
|
+
return this.has(key) ? this.get(key) : defaultValue;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Checks if a key exists
|
|
727
|
+
*/
|
|
728
|
+
has(key) {
|
|
729
|
+
this.ensureNotDestroyed();
|
|
730
|
+
const stringKey = ValidationUtils.sanitizeKey(key);
|
|
731
|
+
return this.data.has(stringKey);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Deletes a key - allows both existing keys and dynamic keys
|
|
735
|
+
*/
|
|
736
|
+
delete(key) {
|
|
737
|
+
this.ensureNotDestroyed();
|
|
738
|
+
this.ensureNotReadOnly();
|
|
739
|
+
const stringKey = ValidationUtils.sanitizeKey(key);
|
|
740
|
+
if (!this.data.has(stringKey)) {
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
// Clean up any secure buffer
|
|
744
|
+
this.cleanupKey(stringKey);
|
|
745
|
+
const deleted = this.data.delete(stringKey);
|
|
746
|
+
this.metadataManager.delete(stringKey);
|
|
747
|
+
this.eventManager.emit("delete", stringKey);
|
|
748
|
+
return deleted;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Cleans up resources associated with a key
|
|
752
|
+
*/
|
|
753
|
+
cleanupKey(key) {
|
|
754
|
+
if (this.secureBuffers.has(key)) {
|
|
755
|
+
this.secureBuffers.get(key)?.destroy();
|
|
756
|
+
this.secureBuffers.delete(key);
|
|
757
|
+
}
|
|
758
|
+
// Note: We don't destroy SecureString or SecureObject instances
|
|
759
|
+
// as they might be used elsewhere
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Clears all data
|
|
763
|
+
*/
|
|
764
|
+
clear() {
|
|
765
|
+
this.ensureNotDestroyed();
|
|
766
|
+
this.ensureNotReadOnly();
|
|
767
|
+
// Destroy all secure buffers
|
|
768
|
+
for (const buffer of this.secureBuffers.values()) {
|
|
769
|
+
buffer.destroy();
|
|
770
|
+
}
|
|
771
|
+
this.secureBuffers.clear();
|
|
772
|
+
this.data.clear();
|
|
773
|
+
this.metadataManager.clear();
|
|
774
|
+
this.eventManager.emit("clear");
|
|
775
|
+
}
|
|
776
|
+
// ===== ITERATION AND COLLECTION METHODS =====
|
|
777
|
+
/**
|
|
778
|
+
* Gets all keys
|
|
779
|
+
*/
|
|
780
|
+
keys() {
|
|
781
|
+
this.ensureNotDestroyed();
|
|
782
|
+
return Array.from(this.data.keys());
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Gets all values
|
|
786
|
+
*/
|
|
787
|
+
values() {
|
|
788
|
+
this.ensureNotDestroyed();
|
|
789
|
+
return this.keys().map((key) => this.get(key));
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Gets all entries as [key, value] pairs
|
|
793
|
+
*/
|
|
794
|
+
entries() {
|
|
795
|
+
this.ensureNotDestroyed();
|
|
796
|
+
return this.keys().map((key) => [key, this.get(key)]);
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Iterates over each key-value pair
|
|
800
|
+
*/
|
|
801
|
+
forEach(callback) {
|
|
802
|
+
this.ensureNotDestroyed();
|
|
803
|
+
ValidationUtils.validateCallback(callback, "forEach callback");
|
|
804
|
+
for (const key of this.keys()) {
|
|
805
|
+
callback(this.get(key), key, this);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Maps over values and returns a new array
|
|
810
|
+
*/
|
|
811
|
+
map(callback) {
|
|
812
|
+
this.ensureNotDestroyed();
|
|
813
|
+
ValidationUtils.validateMapper(callback);
|
|
814
|
+
return this.keys().map((key) => callback(this.get(key), key, this));
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Filters entries based on a predicate function (like Array.filter)
|
|
818
|
+
* Returns a new SecureObject with only the entries that match the condition
|
|
819
|
+
*/
|
|
820
|
+
filter(predicate) {
|
|
821
|
+
this.ensureNotDestroyed();
|
|
822
|
+
ValidationUtils.validatePredicate(predicate);
|
|
823
|
+
const filtered = new SecureObject();
|
|
824
|
+
for (const key of this.keys()) {
|
|
825
|
+
const value = this.get(key);
|
|
826
|
+
if (predicate(value, key, this)) {
|
|
827
|
+
filtered.set(String(key), value);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
// Emit event with filter details
|
|
831
|
+
this.eventManager.emit("filtered", undefined, {
|
|
832
|
+
operation: "filter",
|
|
833
|
+
resultSize: filtered.size,
|
|
834
|
+
originalSize: this.size,
|
|
835
|
+
});
|
|
836
|
+
return filtered;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Filters entries by specific key names (type-safe for known keys)
|
|
840
|
+
* Returns a new SecureObject with only the specified keys
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* const user = createSecureObject({ name: "John", password: "secret", age: 30 });
|
|
844
|
+
* const credentials = user.filterByKeys("name", "password");
|
|
845
|
+
*/
|
|
846
|
+
filterByKeys(...keys) {
|
|
847
|
+
this.ensureNotDestroyed();
|
|
848
|
+
const filtered = new SecureObject();
|
|
849
|
+
for (const key of keys) {
|
|
850
|
+
if (this.has(key)) {
|
|
851
|
+
const stringKey = String(key);
|
|
852
|
+
filtered.set(stringKey, this.get(key));
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
// Copy sensitive keys that are included in the filter
|
|
856
|
+
const relevantSensitiveKeys = this.getSensitiveKeys().filter((k) => keys.includes(k));
|
|
857
|
+
if (relevantSensitiveKeys.length > 0) {
|
|
858
|
+
filtered.setSensitiveKeys(relevantSensitiveKeys);
|
|
859
|
+
}
|
|
860
|
+
this.eventManager.emit("filtered", undefined, {
|
|
861
|
+
operation: "filterByKeys",
|
|
862
|
+
keys: keys.map((k) => String(k)),
|
|
863
|
+
resultSize: filtered.size,
|
|
864
|
+
});
|
|
865
|
+
return filtered;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Filters entries by value type using a type guard function
|
|
869
|
+
* Returns a new SecureObject with only values of the specified type
|
|
870
|
+
*
|
|
871
|
+
* @example
|
|
872
|
+
* const data = createSecureObject({ name: "John", age: 30, active: true });
|
|
873
|
+
* const strings = data.filterByType((v): v is string => typeof v === "string");
|
|
874
|
+
*/
|
|
875
|
+
filterByType(typeGuard) {
|
|
876
|
+
this.ensureNotDestroyed();
|
|
877
|
+
const filtered = new SecureObject();
|
|
878
|
+
for (const key of this.keys()) {
|
|
879
|
+
const value = this.get(key);
|
|
880
|
+
if (typeGuard(value)) {
|
|
881
|
+
const stringKey = String(key);
|
|
882
|
+
filtered.set(stringKey, value);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
this.eventManager.emit("filtered", undefined, {
|
|
886
|
+
operation: "filterByType",
|
|
887
|
+
resultSize: filtered.size,
|
|
888
|
+
});
|
|
889
|
+
return filtered;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Filters entries to only include sensitive keys
|
|
893
|
+
* Returns a new SecureObject with only sensitive data
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* const user = createSecureObject({ name: "John", password: "secret", age: 30 });
|
|
897
|
+
* user.addSensitiveKeys("password");
|
|
898
|
+
* const sensitiveData = user.filterSensitive(); // Only contains password
|
|
899
|
+
*/
|
|
900
|
+
filterSensitive() {
|
|
901
|
+
this.ensureNotDestroyed();
|
|
902
|
+
const filtered = new SecureObject();
|
|
903
|
+
const sensitiveKeys = this.getSensitiveKeys();
|
|
904
|
+
for (const key of this.keys()) {
|
|
905
|
+
const stringKey = String(key);
|
|
906
|
+
if (sensitiveKeys.includes(stringKey)) {
|
|
907
|
+
filtered.set(stringKey, this.get(key));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
// Copy all sensitive keys to the filtered object
|
|
911
|
+
filtered.setSensitiveKeys([...sensitiveKeys]);
|
|
912
|
+
this.eventManager.emit("filtered", undefined, {
|
|
913
|
+
operation: "filterSensitive",
|
|
914
|
+
resultSize: filtered.size,
|
|
915
|
+
});
|
|
916
|
+
return filtered;
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Filters entries to exclude sensitive keys
|
|
920
|
+
* Returns a new SecureObject with only non-sensitive data
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* const user = createSecureObject({ name: "John", password: "secret", age: 30 });
|
|
924
|
+
* user.addSensitiveKeys("password");
|
|
925
|
+
* const publicData = user.filterNonSensitive(); // Contains name and age
|
|
926
|
+
*/
|
|
927
|
+
filterNonSensitive(options) {
|
|
928
|
+
this.ensureNotDestroyed();
|
|
929
|
+
// Default to non-strict mode (false) - only exact matches
|
|
930
|
+
const strictMode = options?.strictMode === true;
|
|
931
|
+
const filtered = new SecureObject();
|
|
932
|
+
for (const key of this.keys()) {
|
|
933
|
+
const stringKey = String(key);
|
|
934
|
+
// Use the enhanced sensitive key detection with strictMode
|
|
935
|
+
if (!this.sensitiveKeysManager.isSensitive(stringKey, strictMode)) {
|
|
936
|
+
const value = this.get(key);
|
|
937
|
+
// If the value is a nested object, process it with the same strictMode
|
|
938
|
+
if (value &&
|
|
939
|
+
typeof value === "object" &&
|
|
940
|
+
value !== null &&
|
|
941
|
+
!Array.isArray(value)) {
|
|
942
|
+
// Process nested object with the same strict mode
|
|
943
|
+
const processedValue = this.processNestedObjectForFiltering(value, strictMode);
|
|
944
|
+
filtered.set(stringKey, processedValue);
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
filtered.set(stringKey, value);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
this.eventManager.emit("filtered", undefined, {
|
|
952
|
+
operation: "filterNonSensitive",
|
|
953
|
+
resultSize: filtered.size,
|
|
954
|
+
});
|
|
955
|
+
return filtered;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Processes nested objects for filtering with the same strict mode
|
|
959
|
+
*/
|
|
960
|
+
processNestedObjectForFiltering(obj, strictMode) {
|
|
961
|
+
if (Array.isArray(obj)) {
|
|
962
|
+
// Handle arrays
|
|
963
|
+
return obj.map((item) => typeof item === "object" && item !== null
|
|
964
|
+
? this.processNestedObjectForFiltering(item, strictMode)
|
|
965
|
+
: item);
|
|
966
|
+
}
|
|
967
|
+
else if (typeof obj === "object" && obj !== null) {
|
|
968
|
+
// Handle objects
|
|
969
|
+
const result = {};
|
|
970
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
971
|
+
if (!this.sensitiveKeysManager.isSensitive(key, strictMode)) {
|
|
972
|
+
if (typeof value === "object" && value !== null) {
|
|
973
|
+
// Recursively process nested objects/arrays
|
|
974
|
+
result[key] = this.processNestedObjectForFiltering(value, strictMode);
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
result[key] = value;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
// If key is sensitive, skip it (don't add to result)
|
|
981
|
+
}
|
|
982
|
+
return result;
|
|
983
|
+
}
|
|
984
|
+
return obj;
|
|
985
|
+
}
|
|
986
|
+
// ===== METADATA OPERATIONS =====
|
|
987
|
+
/**
|
|
988
|
+
* Gets metadata for a specific key
|
|
989
|
+
*/
|
|
990
|
+
getMetadata(key) {
|
|
991
|
+
this.ensureNotDestroyed();
|
|
992
|
+
const stringKey = ValidationUtils.sanitizeKey(key);
|
|
993
|
+
return this.metadataManager.get(stringKey);
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Gets metadata for all keys
|
|
997
|
+
*/
|
|
998
|
+
getAllMetadata() {
|
|
999
|
+
this.ensureNotDestroyed();
|
|
1000
|
+
return this.metadataManager.getAll();
|
|
1001
|
+
}
|
|
1002
|
+
// ===== SERIALIZATION METHODS =====
|
|
1003
|
+
/**
|
|
1004
|
+
* Converts to a regular object with security-focused serialization
|
|
1005
|
+
*
|
|
1006
|
+
* BEHAVIOR: This is the security-focused method that handles sensitive key filtering.
|
|
1007
|
+
* Use this method when you need controlled access to data with security considerations.
|
|
1008
|
+
* For simple object conversion without filtering, use toObject().
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* const user = fObject({
|
|
1012
|
+
id: "1",
|
|
1013
|
+
email: "test@test.com",
|
|
1014
|
+
password: "test123",
|
|
1015
|
+
isVerified: true,
|
|
1016
|
+
userName: "test",
|
|
1017
|
+
firstName: "test",
|
|
1018
|
+
lastName: "test",
|
|
1019
|
+
bio: "test",
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
const getAllResult = user.getAll();
|
|
1023
|
+
console.log("getAllResult.email:", getAllResult.email);
|
|
1024
|
+
console.log("getAllResult.password:", getAllResult.password);
|
|
1025
|
+
console.log("Has password?", "password" in getAllResult);
|
|
1026
|
+
|
|
1027
|
+
// Purpose: Security-conscious data access
|
|
1028
|
+
// Behavior: Filters out sensitive keys by default
|
|
1029
|
+
// Result: password: undefined (filtered for security)
|
|
1030
|
+
// With encryptSensitive: true: ✔ password: "[ENCRYPTED:...]" (encrypted but included)
|
|
1031
|
+
*/
|
|
1032
|
+
getAll(options = {}) {
|
|
1033
|
+
this.ensureNotDestroyed();
|
|
1034
|
+
ValidationUtils.validateSerializationOptions(options);
|
|
1035
|
+
const sensitiveKeys = new Set(this.sensitiveKeysManager.getAll());
|
|
1036
|
+
return this.serializationHandler.toObject(this.data, sensitiveKeys, options);
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Gets the full object as a regular JavaScript object
|
|
1040
|
+
*
|
|
1041
|
+
* BEHAVIOR: Returns ALL data including sensitive keys (like standard JS object conversion).
|
|
1042
|
+
* This method does NOT filter sensitive keys by default - use getAll() for security-focused serialization.
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* const user = fObject({
|
|
1046
|
+
id: "1",
|
|
1047
|
+
email: "test@test.com",
|
|
1048
|
+
password: "test123",
|
|
1049
|
+
isVerified: true,
|
|
1050
|
+
userName: "test",
|
|
1051
|
+
firstName: "test",
|
|
1052
|
+
lastName: "test",
|
|
1053
|
+
bio: "test",
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
const toObjectResult = user.toObject();
|
|
1057
|
+
console.log("toObjectResult.email:", toObjectResult.email);
|
|
1058
|
+
console.log("toObjectResult.password:", toObjectResult.password);
|
|
1059
|
+
console.log("Has password?", "password" in toObjectResult);
|
|
1060
|
+
|
|
1061
|
+
// Purpose: Standard JavaScript object conversion
|
|
1062
|
+
// Behavior: Returns ALL data including sensitive keys (like password)
|
|
1063
|
+
// Result: ✔ password: "test123" (included)
|
|
1064
|
+
|
|
1065
|
+
Sensitive keys can be handled using .add/removeSensitiveKeys()
|
|
1066
|
+
*/
|
|
1067
|
+
toObject(options) {
|
|
1068
|
+
// toObject() should return ALL data by default (no filtering)
|
|
1069
|
+
// Pass an empty Set to indicate no keys should be filtered
|
|
1070
|
+
const noFiltering = new Set();
|
|
1071
|
+
return this.serializationHandler.toObject(this.data, noFiltering, options);
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Converts to JSON string
|
|
1075
|
+
*/
|
|
1076
|
+
toJSON(options = {}) {
|
|
1077
|
+
this.ensureNotDestroyed();
|
|
1078
|
+
ValidationUtils.validateSerializationOptions(options);
|
|
1079
|
+
// Use non-strict mode by default (only exact matches)
|
|
1080
|
+
const strictMode = options.strictSensitiveKeys === true;
|
|
1081
|
+
const isSensitiveKey = (key) => this.sensitiveKeysManager.isSensitive(key, strictMode);
|
|
1082
|
+
return this.serializationHandler.toJSON(this.data, isSensitiveKey, options);
|
|
1083
|
+
}
|
|
1084
|
+
// ===== UTILITY METHODS =====
|
|
1085
|
+
/**
|
|
1086
|
+
* Creates a hash of the entire object content
|
|
1087
|
+
*/
|
|
1088
|
+
async hash(algorithm = "SHA-256", format = "hex") {
|
|
1089
|
+
this.ensureNotDestroyed();
|
|
1090
|
+
const serialized = this.serializationHandler.createHashableRepresentation(this.entries());
|
|
1091
|
+
const secureString = new SecureString(serialized);
|
|
1092
|
+
try {
|
|
1093
|
+
return await secureString.hash(algorithm, format);
|
|
1094
|
+
}
|
|
1095
|
+
finally {
|
|
1096
|
+
secureString.destroy();
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Executes a function with the object data and optionally clears it afterward
|
|
1101
|
+
*/
|
|
1102
|
+
use(fn, autoClear = false) {
|
|
1103
|
+
this.ensureNotDestroyed();
|
|
1104
|
+
ValidationUtils.validateCallback(fn, "use function");
|
|
1105
|
+
try {
|
|
1106
|
+
return fn(this);
|
|
1107
|
+
}
|
|
1108
|
+
finally {
|
|
1109
|
+
if (autoClear) {
|
|
1110
|
+
this.destroy();
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Creates a shallow copy of the SecureObject
|
|
1116
|
+
*/
|
|
1117
|
+
clone() {
|
|
1118
|
+
this.ensureNotDestroyed();
|
|
1119
|
+
return SecureObject.from(this);
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Merges another object into this one
|
|
1123
|
+
*/
|
|
1124
|
+
merge(other, overwrite = true) {
|
|
1125
|
+
this.ensureNotDestroyed();
|
|
1126
|
+
this.ensureNotReadOnly();
|
|
1127
|
+
if (other instanceof SecureObject) {
|
|
1128
|
+
for (const key of other.keys()) {
|
|
1129
|
+
const stringKey = String(key);
|
|
1130
|
+
if (overwrite || !this.has(key)) {
|
|
1131
|
+
this.set(stringKey, other.get(key));
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
else {
|
|
1136
|
+
for (const key in other) {
|
|
1137
|
+
if (Object.prototype.hasOwnProperty.call(other, key)) {
|
|
1138
|
+
if (overwrite || !this.has(key)) {
|
|
1139
|
+
this.set(String(key), other[key]);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
return this;
|
|
1145
|
+
}
|
|
1146
|
+
// ===== AMAZING NEW FEATURES =====
|
|
1147
|
+
/**
|
|
1148
|
+
* Transform values with a mapper function (like Array.map but returns SecureObject)
|
|
1149
|
+
* Returns a new SecureObject with transformed values
|
|
1150
|
+
*/
|
|
1151
|
+
transform(mapper) {
|
|
1152
|
+
this.ensureNotDestroyed();
|
|
1153
|
+
ValidationUtils.validateMapper(mapper);
|
|
1154
|
+
const transformed = new SecureObject();
|
|
1155
|
+
for (const key of this.keys()) {
|
|
1156
|
+
const value = this.get(key);
|
|
1157
|
+
const newValue = mapper(value, key, this);
|
|
1158
|
+
const stringKey = String(key);
|
|
1159
|
+
transformed.set(stringKey, newValue);
|
|
1160
|
+
}
|
|
1161
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1162
|
+
operation: "transform",
|
|
1163
|
+
resultSize: transformed.size,
|
|
1164
|
+
});
|
|
1165
|
+
return transformed;
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Group entries by a classifier function
|
|
1169
|
+
* Returns a Map where keys are group identifiers and values are SecureObjects
|
|
1170
|
+
*/
|
|
1171
|
+
groupBy(classifier) {
|
|
1172
|
+
this.ensureNotDestroyed();
|
|
1173
|
+
ValidationUtils.validateCallback(classifier, "Classifier function");
|
|
1174
|
+
const groups = new Map();
|
|
1175
|
+
for (const key of this.keys()) {
|
|
1176
|
+
const value = this.get(key);
|
|
1177
|
+
const groupKey = classifier(value, key);
|
|
1178
|
+
if (!groups.has(groupKey)) {
|
|
1179
|
+
groups.set(groupKey, new SecureObject());
|
|
1180
|
+
}
|
|
1181
|
+
const group = groups.get(groupKey);
|
|
1182
|
+
const stringKey = String(key);
|
|
1183
|
+
group.set(stringKey, value);
|
|
1184
|
+
}
|
|
1185
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1186
|
+
operation: "groupBy",
|
|
1187
|
+
resultSize: groups.size,
|
|
1188
|
+
});
|
|
1189
|
+
return groups;
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Partition entries into two groups based on a predicate
|
|
1193
|
+
* Returns [matching, notMatching] SecureObjects
|
|
1194
|
+
*/
|
|
1195
|
+
partition(predicate) {
|
|
1196
|
+
this.ensureNotDestroyed();
|
|
1197
|
+
ValidationUtils.validatePredicate(predicate);
|
|
1198
|
+
const matching = new SecureObject();
|
|
1199
|
+
const notMatching = new SecureObject();
|
|
1200
|
+
for (const key of this.keys()) {
|
|
1201
|
+
const value = this.get(key);
|
|
1202
|
+
const stringKey = String(key);
|
|
1203
|
+
if (predicate(value, key)) {
|
|
1204
|
+
matching.set(stringKey, value);
|
|
1205
|
+
}
|
|
1206
|
+
else {
|
|
1207
|
+
notMatching.set(stringKey, value);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1211
|
+
operation: "partition",
|
|
1212
|
+
resultSize: matching.size + notMatching.size,
|
|
1213
|
+
});
|
|
1214
|
+
return [matching, notMatching];
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Pick specific keys (like Lodash pick but type-safe)
|
|
1218
|
+
* Returns a new SecureObject with only the specified keys
|
|
1219
|
+
*/
|
|
1220
|
+
pick(...keys) {
|
|
1221
|
+
return this.filterByKeys(...keys);
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Omit specific keys (opposite of pick)
|
|
1225
|
+
* Returns a new SecureObject without the specified keys
|
|
1226
|
+
*/
|
|
1227
|
+
omit(...keys) {
|
|
1228
|
+
this.ensureNotDestroyed();
|
|
1229
|
+
const omitted = new SecureObject();
|
|
1230
|
+
const keysToOmit = new Set(keys.map((k) => String(k)));
|
|
1231
|
+
for (const key of this.keys()) {
|
|
1232
|
+
const stringKey = String(key);
|
|
1233
|
+
if (!keysToOmit.has(stringKey)) {
|
|
1234
|
+
omitted.set(stringKey, this.get(key));
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1238
|
+
operation: "omit",
|
|
1239
|
+
keys: keys.map((k) => String(k)),
|
|
1240
|
+
resultSize: omitted.size,
|
|
1241
|
+
});
|
|
1242
|
+
return omitted;
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Flatten nested objects (one level deep)
|
|
1246
|
+
* Converts { user: { name: "John" } } to { "user.name": "John" }
|
|
1247
|
+
*/
|
|
1248
|
+
flatten(separator = ".") {
|
|
1249
|
+
this.ensureNotDestroyed();
|
|
1250
|
+
const flattened = new SecureObject();
|
|
1251
|
+
for (const key of this.keys()) {
|
|
1252
|
+
const value = this.get(key);
|
|
1253
|
+
const stringKey = String(key);
|
|
1254
|
+
if (value &&
|
|
1255
|
+
typeof value === "object" &&
|
|
1256
|
+
!Array.isArray(value) &&
|
|
1257
|
+
!(value instanceof Date)) {
|
|
1258
|
+
// Flatten nested object
|
|
1259
|
+
for (const [nestedKey, nestedValue] of Object.entries(value)) {
|
|
1260
|
+
const flatKey = `${stringKey}${separator}${nestedKey}`;
|
|
1261
|
+
flattened.set(flatKey, nestedValue);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
else {
|
|
1265
|
+
flattened.set(stringKey, value);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1269
|
+
operation: "flatten",
|
|
1270
|
+
resultSize: flattened.size,
|
|
1271
|
+
});
|
|
1272
|
+
return flattened;
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Compact - removes null, undefined, and empty values
|
|
1276
|
+
* Returns a new SecureObject with only truthy values
|
|
1277
|
+
*/
|
|
1278
|
+
compact() {
|
|
1279
|
+
return this.filter((value) => {
|
|
1280
|
+
if (value === null || value === undefined)
|
|
1281
|
+
return false;
|
|
1282
|
+
if (typeof value === "string" && value.trim() === "")
|
|
1283
|
+
return false;
|
|
1284
|
+
if (Array.isArray(value) && value.length === 0)
|
|
1285
|
+
return false;
|
|
1286
|
+
if (typeof value === "object" && Object.keys(value).length === 0)
|
|
1287
|
+
return false;
|
|
1288
|
+
return true;
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Invert - swap keys and values
|
|
1293
|
+
* Returns a new SecureObject with keys and values swapped
|
|
1294
|
+
*/
|
|
1295
|
+
invert() {
|
|
1296
|
+
this.ensureNotDestroyed();
|
|
1297
|
+
const inverted = new SecureObject();
|
|
1298
|
+
for (const key of this.keys()) {
|
|
1299
|
+
const value = this.get(key);
|
|
1300
|
+
const stringValue = String(value);
|
|
1301
|
+
const stringKey = String(key);
|
|
1302
|
+
inverted.set(stringValue, stringKey);
|
|
1303
|
+
}
|
|
1304
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1305
|
+
operation: "invert",
|
|
1306
|
+
resultSize: inverted.size,
|
|
1307
|
+
});
|
|
1308
|
+
return inverted;
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Defaults - merge with default values (only for missing keys)
|
|
1312
|
+
* Returns a new SecureObject with defaults applied
|
|
1313
|
+
*/
|
|
1314
|
+
defaults(defaultValues) {
|
|
1315
|
+
this.ensureNotDestroyed();
|
|
1316
|
+
const result = new SecureObject();
|
|
1317
|
+
// First, copy all existing values
|
|
1318
|
+
for (const key of this.keys()) {
|
|
1319
|
+
const stringKey = String(key);
|
|
1320
|
+
result.set(stringKey, this.get(key));
|
|
1321
|
+
}
|
|
1322
|
+
// Then, add defaults for missing keys
|
|
1323
|
+
for (const [key, value] of Object.entries(defaultValues)) {
|
|
1324
|
+
if (!this.has(key)) {
|
|
1325
|
+
result.set(key, value);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1329
|
+
operation: "defaults",
|
|
1330
|
+
resultSize: result.size,
|
|
1331
|
+
});
|
|
1332
|
+
return result;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Tap - execute a function with the object and return the object (for chaining)
|
|
1336
|
+
* Useful for debugging or side effects in method chains
|
|
1337
|
+
*/
|
|
1338
|
+
tap(fn) {
|
|
1339
|
+
this.ensureNotDestroyed();
|
|
1340
|
+
ValidationUtils.validateCallback(fn, "Tap function");
|
|
1341
|
+
fn(this);
|
|
1342
|
+
return this;
|
|
1343
|
+
}
|
|
1344
|
+
pipe(...fns) {
|
|
1345
|
+
this.ensureNotDestroyed();
|
|
1346
|
+
return fns.reduce((result, fn) => {
|
|
1347
|
+
ValidationUtils.validateCallback(fn, "Pipe function");
|
|
1348
|
+
return fn(result);
|
|
1349
|
+
}, this);
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Sample - get random entries from the object
|
|
1353
|
+
* Returns a new SecureObject with randomly selected entries
|
|
1354
|
+
*/
|
|
1355
|
+
sample(count = 1) {
|
|
1356
|
+
this.ensureNotDestroyed();
|
|
1357
|
+
if (count <= 0) {
|
|
1358
|
+
return new SecureObject();
|
|
1359
|
+
}
|
|
1360
|
+
const allKeys = this.keys();
|
|
1361
|
+
const sampleSize = Math.min(count, allKeys.length);
|
|
1362
|
+
const sampledKeys = [];
|
|
1363
|
+
// Simple random sampling without replacement
|
|
1364
|
+
const availableKeys = [...allKeys];
|
|
1365
|
+
for (let i = 0; i < sampleSize; i++) {
|
|
1366
|
+
const randomIndex = Math.floor(Math.random() * availableKeys.length);
|
|
1367
|
+
sampledKeys.push(availableKeys.splice(randomIndex, 1)[0]);
|
|
1368
|
+
}
|
|
1369
|
+
const sampled = new SecureObject();
|
|
1370
|
+
for (const key of sampledKeys) {
|
|
1371
|
+
const stringKey = String(key);
|
|
1372
|
+
sampled.set(stringKey, this.get(key));
|
|
1373
|
+
}
|
|
1374
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1375
|
+
operation: "sample",
|
|
1376
|
+
resultSize: sampled.size,
|
|
1377
|
+
});
|
|
1378
|
+
return sampled;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Shuffle - return a new SecureObject with keys in random order
|
|
1382
|
+
* Returns a new SecureObject with the same data but shuffled key order
|
|
1383
|
+
*/
|
|
1384
|
+
shuffle() {
|
|
1385
|
+
this.ensureNotDestroyed();
|
|
1386
|
+
const allKeys = this.keys();
|
|
1387
|
+
const shuffledKeys = [...allKeys];
|
|
1388
|
+
// Fisher-Yates shuffle
|
|
1389
|
+
for (let i = shuffledKeys.length - 1; i > 0; i--) {
|
|
1390
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
1391
|
+
[shuffledKeys[i], shuffledKeys[j]] = [
|
|
1392
|
+
shuffledKeys[j],
|
|
1393
|
+
shuffledKeys[i],
|
|
1394
|
+
];
|
|
1395
|
+
}
|
|
1396
|
+
const shuffled = new SecureObject();
|
|
1397
|
+
for (const key of shuffledKeys) {
|
|
1398
|
+
const stringKey = String(key);
|
|
1399
|
+
shuffled.set(stringKey, this.get(key));
|
|
1400
|
+
}
|
|
1401
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1402
|
+
operation: "shuffle",
|
|
1403
|
+
resultSize: shuffled.size,
|
|
1404
|
+
});
|
|
1405
|
+
return shuffled;
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Chunk - split object into chunks of specified size
|
|
1409
|
+
* Returns an array of SecureObjects, each containing up to 'size' entries
|
|
1410
|
+
*/
|
|
1411
|
+
chunk(size) {
|
|
1412
|
+
this.ensureNotDestroyed();
|
|
1413
|
+
if (size <= 0) {
|
|
1414
|
+
throw new Error("Chunk size must be greater than 0");
|
|
1415
|
+
}
|
|
1416
|
+
const allKeys = this.keys();
|
|
1417
|
+
const chunks = [];
|
|
1418
|
+
for (let i = 0; i < allKeys.length; i += size) {
|
|
1419
|
+
const chunk = new SecureObject();
|
|
1420
|
+
const chunkKeys = allKeys.slice(i, i + size);
|
|
1421
|
+
for (const key of chunkKeys) {
|
|
1422
|
+
const stringKey = String(key);
|
|
1423
|
+
chunk.set(stringKey, this.get(key));
|
|
1424
|
+
}
|
|
1425
|
+
chunks.push(chunk);
|
|
1426
|
+
}
|
|
1427
|
+
this.eventManager.emit("filtered", undefined, {
|
|
1428
|
+
operation: "chunk",
|
|
1429
|
+
resultSize: chunks.length,
|
|
1430
|
+
});
|
|
1431
|
+
return chunks;
|
|
1432
|
+
}
|
|
1433
|
+
// ===== SERIALIZATION AND EXPORT =====
|
|
1434
|
+
/**
|
|
1435
|
+
* Serializes the SecureObject to a secure format
|
|
1436
|
+
*/
|
|
1437
|
+
serialize(options = {}) {
|
|
1438
|
+
this.ensureNotDestroyed();
|
|
1439
|
+
try {
|
|
1440
|
+
const { includeMetadata = true, encryptSensitive = false, format = "json", } = options;
|
|
1441
|
+
// Create serialization package
|
|
1442
|
+
const package_ = {
|
|
1443
|
+
version: "2.0.0",
|
|
1444
|
+
format: "XyPrissSecurity-SecureObject",
|
|
1445
|
+
timestamp: Date.now(),
|
|
1446
|
+
objectId: this._id,
|
|
1447
|
+
data: this.serializationHandler.toObject(this.data, (key) => this.sensitiveKeysManager.isSensitive(key, true), // Use strict mode
|
|
1448
|
+
options),
|
|
1449
|
+
metadata: includeMetadata
|
|
1450
|
+
? this.getSerializationMetadata()
|
|
1451
|
+
: null,
|
|
1452
|
+
size: this.size,
|
|
1453
|
+
isReadOnly: this._isReadOnly,
|
|
1454
|
+
encryptionEnabled: this.cryptoHandler.getEncryptionStatus().hasEncryptionKey,
|
|
1455
|
+
};
|
|
1456
|
+
// Return as JSON string or binary based on format
|
|
1457
|
+
if (format === "binary") {
|
|
1458
|
+
const jsonString = JSON.stringify(package_);
|
|
1459
|
+
const binaryData = new TextEncoder().encode(jsonString);
|
|
1460
|
+
return Array.from(binaryData)
|
|
1461
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
1462
|
+
.join("");
|
|
1463
|
+
}
|
|
1464
|
+
else {
|
|
1465
|
+
return JSON.stringify(package_, null, 2);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
catch (error) {
|
|
1469
|
+
console.error("Serialization failed:", error);
|
|
1470
|
+
throw new Error(`Serialization failed: ${error.message}`);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Exports the SecureObject data in various formats
|
|
1475
|
+
*/
|
|
1476
|
+
exportData(format = "json") {
|
|
1477
|
+
this.ensureNotDestroyed();
|
|
1478
|
+
try {
|
|
1479
|
+
const data = this.toObject();
|
|
1480
|
+
switch (format) {
|
|
1481
|
+
case "json":
|
|
1482
|
+
return JSON.stringify(data, null, 2);
|
|
1483
|
+
case "csv":
|
|
1484
|
+
return this.exportToCSV(data);
|
|
1485
|
+
case "xml":
|
|
1486
|
+
return this.exportToXML(data);
|
|
1487
|
+
case "yaml":
|
|
1488
|
+
return this.exportToYAML(data);
|
|
1489
|
+
default:
|
|
1490
|
+
throw new Error(`Unsupported export format: ${format}`);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
catch (error) {
|
|
1494
|
+
console.error("Export failed:", error);
|
|
1495
|
+
throw new Error(`Export failed: ${error.message}`);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Gets serialization metadata
|
|
1500
|
+
*/
|
|
1501
|
+
getSerializationMetadata() {
|
|
1502
|
+
const stats = this.metadataManager.getStats();
|
|
1503
|
+
const memoryUsage = this.getMemoryUsage();
|
|
1504
|
+
return {
|
|
1505
|
+
totalEntries: stats.totalEntries,
|
|
1506
|
+
secureEntries: stats.secureEntries,
|
|
1507
|
+
memoryUsage: memoryUsage.allocatedMemory,
|
|
1508
|
+
lastModified: stats.newestEntry?.getTime() || this._createdAt,
|
|
1509
|
+
createdAt: this._createdAt,
|
|
1510
|
+
accessCount: stats.totalAccesses,
|
|
1511
|
+
averageAccesses: stats.averageAccesses,
|
|
1512
|
+
oldestEntry: stats.oldestEntry?.getTime() || null,
|
|
1513
|
+
newestEntry: stats.newestEntry?.getTime() || null,
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Exports to CSV format
|
|
1518
|
+
*/
|
|
1519
|
+
exportToCSV(data) {
|
|
1520
|
+
const entries = Object.entries(data);
|
|
1521
|
+
if (entries.length === 0)
|
|
1522
|
+
return "Key,Value,Type\n";
|
|
1523
|
+
let csv = "Key,Value,Type\n";
|
|
1524
|
+
for (const [key, value] of entries) {
|
|
1525
|
+
const type = typeof value;
|
|
1526
|
+
const valueStr = type === "object" ? JSON.stringify(value) : String(value);
|
|
1527
|
+
const escapedValue = `"${valueStr.replace(/"/g, '""')}"`;
|
|
1528
|
+
csv += `"${key}",${escapedValue},${type}\n`;
|
|
1529
|
+
}
|
|
1530
|
+
return csv;
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Exports to XML format
|
|
1534
|
+
*/
|
|
1535
|
+
exportToXML(data) {
|
|
1536
|
+
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n<SecureObject>\n';
|
|
1537
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1538
|
+
const type = typeof value;
|
|
1539
|
+
const valueStr = type === "object" ? JSON.stringify(value) : String(value);
|
|
1540
|
+
xml += ` <entry key="${this.escapeXML(key)}" type="${type}">${this.escapeXML(valueStr)}</entry>\n`;
|
|
1541
|
+
}
|
|
1542
|
+
xml += "</SecureObject>";
|
|
1543
|
+
return xml;
|
|
1544
|
+
}
|
|
1545
|
+
/**
|
|
1546
|
+
* Exports to YAML format
|
|
1547
|
+
*/
|
|
1548
|
+
exportToYAML(data) {
|
|
1549
|
+
let yaml = "# SecureObject Export\n";
|
|
1550
|
+
yaml += `# Generated: ${new Date().toISOString()}\n\n`;
|
|
1551
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1552
|
+
const type = typeof value;
|
|
1553
|
+
if (type === "object") {
|
|
1554
|
+
yaml += `${key}:\n`;
|
|
1555
|
+
yaml += ` value: ${JSON.stringify(value)}\n`;
|
|
1556
|
+
yaml += ` type: ${type}\n\n`;
|
|
1557
|
+
}
|
|
1558
|
+
else {
|
|
1559
|
+
yaml += `${key}: ${JSON.stringify(value)}\n`;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
return yaml;
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Escapes XML special characters
|
|
1566
|
+
*/
|
|
1567
|
+
escapeXML(str) {
|
|
1568
|
+
return str
|
|
1569
|
+
.replace(/&/g, "&")
|
|
1570
|
+
.replace(/</g, "<")
|
|
1571
|
+
.replace(/>/g, ">")
|
|
1572
|
+
.replace(/"/g, """)
|
|
1573
|
+
.replace(/'/g, "'");
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Destroys the SecureObject and clears all data
|
|
1577
|
+
*/
|
|
1578
|
+
destroy() {
|
|
1579
|
+
if (!this._isDestroyed) {
|
|
1580
|
+
// Clean up memory tracking
|
|
1581
|
+
if (this._memoryTracking) {
|
|
1582
|
+
memoryManager.removeReference(this._id);
|
|
1583
|
+
}
|
|
1584
|
+
this.clear();
|
|
1585
|
+
this.eventManager.clear();
|
|
1586
|
+
this._isDestroyed = true;
|
|
1587
|
+
this.eventManager.emit("destroy");
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
/**
|
|
1591
|
+
* Custom inspection for debugging (masks sensitive data)
|
|
1592
|
+
*/
|
|
1593
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
1594
|
+
if (this._isDestroyed) {
|
|
1595
|
+
return "SecureObject [DESTROYED]";
|
|
1596
|
+
}
|
|
1597
|
+
const stats = this.metadataManager.getStats();
|
|
1598
|
+
return `SecureObject [${this.size} items, ${stats.secureEntries} secure] ${this._isReadOnly ? "[READ-ONLY]" : ""}`;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
export { SecureObject };
|
|
1603
|
+
//# sourceMappingURL=secure-object-core.js.map
|