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.
Files changed (570) hide show
  1. package/README.md +187 -84
  2. package/dist/cjs/ServerFactory.js +1 -1
  3. package/dist/cjs/cache/SecureCacheAdapter.js +2 -2
  4. package/dist/cjs/cluster/cluster-manager.js +1 -1
  5. package/dist/cjs/cluster/index.js +30 -30
  6. package/dist/cjs/cluster/modules/AutoScaler.js +2 -2
  7. package/dist/cjs/cluster/modules/ClusterPersistenceManager.js +3 -3
  8. package/dist/cjs/cluster/modules/HealthMonitor.js +2 -2
  9. package/dist/cjs/cluster/modules/IPCManager.js +2 -2
  10. package/dist/cjs/cluster/modules/MetricsCollector.js +1 -1
  11. package/dist/cjs/cluster/modules/WorkerManager.js +2 -2
  12. package/dist/cjs/encryption/EncryptionService.js +12 -12
  13. package/dist/cjs/encryption/EncryptionService.js.map +1 -1
  14. package/dist/cjs/index.js +1 -1
  15. package/dist/cjs/middleware/safe-json-middleware.js +1 -1
  16. package/dist/cjs/mods/security/src/algorithms/hash-algorithms.js +727 -0
  17. package/dist/cjs/mods/security/src/algorithms/hash-algorithms.js.map +1 -0
  18. package/dist/cjs/mods/security/src/algorithms/registry.js +83 -0
  19. package/dist/cjs/mods/security/src/algorithms/registry.js.map +1 -0
  20. package/dist/cjs/mods/security/src/components/attestation.js +1065 -0
  21. package/dist/cjs/mods/security/src/components/attestation.js.map +1 -0
  22. package/dist/cjs/mods/security/src/components/cache/FastLRU.js +323 -0
  23. package/dist/cjs/mods/security/src/components/cache/FastLRU.js.map +1 -0
  24. package/dist/cjs/mods/security/src/components/cache/UFSIMC.js +1131 -0
  25. package/dist/cjs/mods/security/src/components/cache/UFSIMC.js.map +1 -0
  26. package/dist/cjs/mods/security/src/components/cache/cacheSys.js +624 -0
  27. package/dist/cjs/mods/security/src/components/cache/cacheSys.js.map +1 -0
  28. package/dist/cjs/mods/security/src/components/cache/cacheSys.utils.js +136 -0
  29. package/dist/cjs/mods/security/src/components/cache/cacheSys.utils.js.map +1 -0
  30. package/dist/cjs/mods/security/src/components/cache/config/cache.config.js +39 -0
  31. package/dist/cjs/mods/security/src/components/cache/config/cache.config.js.map +1 -0
  32. package/dist/cjs/mods/security/src/components/cache/index.js +459 -0
  33. package/dist/cjs/mods/security/src/components/cache/index.js.map +1 -0
  34. package/dist/cjs/mods/security/src/components/cache/useCache.js +243 -0
  35. package/dist/cjs/mods/security/src/components/cache/useCache.js.map +1 -0
  36. package/dist/cjs/mods/security/src/components/canary-tokens.js +351 -0
  37. package/dist/cjs/mods/security/src/components/canary-tokens.js.map +1 -0
  38. package/dist/cjs/mods/security/src/components/entropy-augmentation.js +478 -0
  39. package/dist/cjs/mods/security/src/components/entropy-augmentation.js.map +1 -0
  40. package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js +338 -0
  41. package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js.map +1 -0
  42. package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js +536 -0
  43. package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js.map +1 -0
  44. package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js +631 -0
  45. package/dist/cjs/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js.map +1 -0
  46. package/dist/cjs/mods/security/src/components/fortified-function/const/exec.const.js +18 -0
  47. package/dist/cjs/mods/security/src/components/fortified-function/const/exec.const.js.map +1 -0
  48. package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-config.js +356 -0
  49. package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-config.js.map +1 -0
  50. package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-function-core.js +520 -0
  51. package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-function-core.js.map +1 -0
  52. package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-logger.js +246 -0
  53. package/dist/cjs/mods/security/src/components/fortified-function/core/fortified-logger.js.map +1 -0
  54. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/api-manager.js +189 -0
  55. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/api-manager.js.map +1 -0
  56. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/cache-manager.js +107 -0
  57. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/cache-manager.js.map +1 -0
  58. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-context.js +105 -0
  59. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-context.js.map +1 -0
  60. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-engine.js +127 -0
  61. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-engine.js.map +1 -0
  62. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-router.js +93 -0
  63. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/execution-router.js.map +1 -0
  64. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/memory-manager.js +147 -0
  65. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/memory-manager.js.map +1 -0
  66. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/security-manager.js +102 -0
  67. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/security-manager.js.map +1 -0
  68. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/stats-manager.js +159 -0
  69. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/stats-manager.js.map +1 -0
  70. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/timing-manager.js +125 -0
  71. package/dist/cjs/mods/security/src/components/fortified-function/core/mods/timing-manager.js.map +1 -0
  72. package/dist/cjs/mods/security/src/components/fortified-function/engines/analytics-engine.js +370 -0
  73. package/dist/cjs/mods/security/src/components/fortified-function/engines/analytics-engine.js.map +1 -0
  74. package/dist/cjs/mods/security/src/components/fortified-function/engines/execution-engine.js +402 -0
  75. package/dist/cjs/mods/security/src/components/fortified-function/engines/execution-engine.js.map +1 -0
  76. package/dist/cjs/mods/security/src/components/fortified-function/index.js +172 -0
  77. package/dist/cjs/mods/security/src/components/fortified-function/index.js.map +1 -0
  78. package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-monitor.js +240 -0
  79. package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-monitor.js.map +1 -0
  80. package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-timer.js +188 -0
  81. package/dist/cjs/mods/security/src/components/fortified-function/performance/performance-timer.js.map +1 -0
  82. package/dist/cjs/mods/security/src/components/fortified-function/security/security-handler.js +253 -0
  83. package/dist/cjs/mods/security/src/components/fortified-function/security/security-handler.js.map +1 -0
  84. package/dist/cjs/mods/security/src/components/fortified-function/serializer/safe-serializer.js +350 -0
  85. package/dist/cjs/mods/security/src/components/fortified-function/serializer/safe-serializer.js.map +1 -0
  86. package/dist/cjs/mods/security/src/components/fortified-function/smart-cache.js +693 -0
  87. package/dist/cjs/mods/security/src/components/fortified-function/smart-cache.js.map +1 -0
  88. package/dist/cjs/mods/security/src/components/fortified-function/types/types.js +16 -0
  89. package/dist/cjs/mods/security/src/components/fortified-function/types/types.js.map +1 -0
  90. package/dist/cjs/mods/security/src/components/fortified-function/utils/utils.js +68 -0
  91. package/dist/cjs/mods/security/src/components/fortified-function/utils/utils.js.map +1 -0
  92. package/dist/cjs/mods/security/src/components/memory-hard.js +922 -0
  93. package/dist/cjs/mods/security/src/components/memory-hard.js.map +1 -0
  94. package/dist/cjs/mods/security/src/components/post-quantum.js +323 -0
  95. package/dist/cjs/mods/security/src/components/post-quantum.js.map +1 -0
  96. package/dist/cjs/mods/security/src/components/runtime-verification.js +645 -0
  97. package/dist/cjs/mods/security/src/components/runtime-verification.js.map +1 -0
  98. package/dist/cjs/mods/security/src/components/secure-array/core/secure-array-core.js +1572 -0
  99. package/dist/cjs/mods/security/src/components/secure-array/core/secure-array-core.js.map +1 -0
  100. package/dist/cjs/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js +330 -0
  101. package/dist/cjs/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js.map +1 -0
  102. package/dist/cjs/mods/security/src/components/secure-array/events/event-manager.js +270 -0
  103. package/dist/cjs/mods/security/src/components/secure-array/events/event-manager.js.map +1 -0
  104. package/dist/cjs/mods/security/src/components/secure-array/index.js +66 -0
  105. package/dist/cjs/mods/security/src/components/secure-array/index.js.map +1 -0
  106. package/dist/cjs/mods/security/src/components/secure-array/metadata/metadata-manager.js +331 -0
  107. package/dist/cjs/mods/security/src/components/secure-array/metadata/metadata-manager.js.map +1 -0
  108. package/dist/cjs/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js +390 -0
  109. package/dist/cjs/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js.map +1 -0
  110. package/dist/cjs/mods/security/src/components/secure-array/types/index.js +87 -0
  111. package/dist/cjs/mods/security/src/components/secure-array/types/index.js.map +1 -0
  112. package/dist/cjs/mods/security/src/components/secure-array/utils/id-generator.js +80 -0
  113. package/dist/cjs/mods/security/src/components/secure-array/utils/id-generator.js.map +1 -0
  114. package/dist/cjs/mods/security/src/components/secure-array/utils/validation.js +275 -0
  115. package/dist/cjs/mods/security/src/components/secure-array/utils/validation.js.map +1 -0
  116. package/dist/cjs/mods/security/src/components/secure-memory.js +906 -0
  117. package/dist/cjs/mods/security/src/components/secure-memory.js.map +1 -0
  118. package/dist/cjs/mods/security/src/components/secure-object/core/secure-object-core.js +1605 -0
  119. package/dist/cjs/mods/security/src/components/secure-object/core/secure-object-core.js.map +1 -0
  120. package/dist/cjs/mods/security/src/components/secure-object/encryption/crypto-handler.js +362 -0
  121. package/dist/cjs/mods/security/src/components/secure-object/encryption/crypto-handler.js.map +1 -0
  122. package/dist/cjs/mods/security/src/components/secure-object/encryption/sensitive-keys.js +206 -0
  123. package/dist/cjs/mods/security/src/components/secure-object/encryption/sensitive-keys.js.map +1 -0
  124. package/dist/cjs/mods/security/src/components/secure-object/events/event-manager.js +197 -0
  125. package/dist/cjs/mods/security/src/components/secure-object/events/event-manager.js.map +1 -0
  126. package/dist/cjs/mods/security/src/components/secure-object/index.js +67 -0
  127. package/dist/cjs/mods/security/src/components/secure-object/index.js.map +1 -0
  128. package/dist/cjs/mods/security/src/components/secure-object/metadata/metadata-manager.js +183 -0
  129. package/dist/cjs/mods/security/src/components/secure-object/metadata/metadata-manager.js.map +1 -0
  130. package/dist/cjs/mods/security/src/components/secure-object/serialization/serialization-handler.js +197 -0
  131. package/dist/cjs/mods/security/src/components/secure-object/serialization/serialization-handler.js.map +1 -0
  132. package/dist/cjs/mods/security/src/components/secure-object/utils/id-generator.js +64 -0
  133. package/dist/cjs/mods/security/src/components/secure-object/utils/id-generator.js.map +1 -0
  134. package/dist/cjs/mods/security/src/components/secure-object/utils/validation.js +239 -0
  135. package/dist/cjs/mods/security/src/components/secure-object/utils/validation.js.map +1 -0
  136. package/dist/cjs/mods/security/src/components/secure-serialization.js +772 -0
  137. package/dist/cjs/mods/security/src/components/secure-serialization.js.map +1 -0
  138. package/dist/cjs/mods/security/src/components/secure-string/advanced/entropy-analyzer.js +308 -0
  139. package/dist/cjs/mods/security/src/components/secure-string/advanced/entropy-analyzer.js.map +1 -0
  140. package/dist/cjs/mods/security/src/components/secure-string/advanced/performance-monitor.js +335 -0
  141. package/dist/cjs/mods/security/src/components/secure-string/advanced/performance-monitor.js.map +1 -0
  142. package/dist/cjs/mods/security/src/components/secure-string/advanced/quantum-safe.js +245 -0
  143. package/dist/cjs/mods/security/src/components/secure-string/advanced/quantum-safe.js.map +1 -0
  144. package/dist/cjs/mods/security/src/components/secure-string/buffer/buffer-manager.js +205 -0
  145. package/dist/cjs/mods/security/src/components/secure-string/buffer/buffer-manager.js.map +1 -0
  146. package/dist/cjs/mods/security/src/components/secure-string/core/secure-string-core.js +788 -0
  147. package/dist/cjs/mods/security/src/components/secure-string/core/secure-string-core.js.map +1 -0
  148. package/dist/cjs/mods/security/src/components/secure-string/crypto/crypto-operations.js +319 -0
  149. package/dist/cjs/mods/security/src/components/secure-string/crypto/crypto-operations.js.map +1 -0
  150. package/dist/cjs/mods/security/src/components/secure-string/operations/comparison-operations.js +221 -0
  151. package/dist/cjs/mods/security/src/components/secure-string/operations/comparison-operations.js.map +1 -0
  152. package/dist/cjs/mods/security/src/components/secure-string/operations/string-operations.js +234 -0
  153. package/dist/cjs/mods/security/src/components/secure-string/operations/string-operations.js.map +1 -0
  154. package/dist/cjs/mods/security/src/components/secure-string/types/index.js +41 -0
  155. package/dist/cjs/mods/security/src/components/secure-string/types/index.js.map +1 -0
  156. package/dist/cjs/mods/security/src/components/secure-string/validation/string-validator.js +334 -0
  157. package/dist/cjs/mods/security/src/components/secure-string/validation/string-validator.js.map +1 -0
  158. package/dist/cjs/mods/security/src/components/side-channel.js +146 -0
  159. package/dist/cjs/mods/security/src/components/side-channel.js.map +1 -0
  160. package/dist/cjs/mods/security/src/components/tamper-evident-logging.js +391 -0
  161. package/dist/cjs/mods/security/src/components/tamper-evident-logging.js.map +1 -0
  162. package/dist/cjs/mods/security/src/const/buffer.const.js +15 -0
  163. package/dist/cjs/mods/security/src/const/buffer.const.js.map +1 -0
  164. package/dist/cjs/mods/security/src/core/crypto.js +722 -0
  165. package/dist/cjs/mods/security/src/core/crypto.js.map +1 -0
  166. package/dist/cjs/mods/security/src/core/hash/hash-advanced.js +388 -0
  167. package/dist/cjs/mods/security/src/core/hash/hash-advanced.js.map +1 -0
  168. package/dist/cjs/mods/security/src/core/hash/hash-core.js +376 -0
  169. package/dist/cjs/mods/security/src/core/hash/hash-core.js.map +1 -0
  170. package/dist/cjs/mods/security/src/core/hash/hash-entropy.js +307 -0
  171. package/dist/cjs/mods/security/src/core/hash/hash-entropy.js.map +1 -0
  172. package/dist/cjs/mods/security/src/core/hash/hash-security.js +372 -0
  173. package/dist/cjs/mods/security/src/core/hash/hash-security.js.map +1 -0
  174. package/dist/cjs/mods/security/src/core/hash/hash-types.js +16 -0
  175. package/dist/cjs/mods/security/src/core/hash/hash-types.js.map +1 -0
  176. package/dist/cjs/mods/security/src/core/hash/hash-utils.js +328 -0
  177. package/dist/cjs/mods/security/src/core/hash/hash-utils.js.map +1 -0
  178. package/dist/cjs/mods/security/src/core/hash/hash-validator.js +312 -0
  179. package/dist/cjs/mods/security/src/core/hash/hash-validator.js.map +1 -0
  180. package/dist/cjs/mods/security/src/core/hash.js +25 -0
  181. package/dist/cjs/mods/security/src/core/hash.js.map +1 -0
  182. package/dist/cjs/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js +135 -0
  183. package/dist/cjs/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js.map +1 -0
  184. package/dist/cjs/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js +293 -0
  185. package/dist/cjs/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js.map +1 -0
  186. package/dist/cjs/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js +317 -0
  187. package/dist/cjs/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js.map +1 -0
  188. package/dist/cjs/mods/security/src/core/keys/keys-core.js +201 -0
  189. package/dist/cjs/mods/security/src/core/keys/keys-core.js.map +1 -0
  190. package/dist/cjs/mods/security/src/core/keys/keys-logger.js +234 -0
  191. package/dist/cjs/mods/security/src/core/keys/keys-logger.js.map +1 -0
  192. package/dist/cjs/mods/security/src/core/keys/keys-types.js +65 -0
  193. package/dist/cjs/mods/security/src/core/keys/keys-types.js.map +1 -0
  194. package/dist/cjs/mods/security/src/core/keys/keys-utils.js +322 -0
  195. package/dist/cjs/mods/security/src/core/keys/keys-utils.js.map +1 -0
  196. package/dist/cjs/mods/security/src/core/keys.js +136 -0
  197. package/dist/cjs/mods/security/src/core/keys.js.map +1 -0
  198. package/dist/cjs/mods/security/src/core/password/index.js +122 -0
  199. package/dist/cjs/mods/security/src/core/password/index.js.map +1 -0
  200. package/dist/cjs/mods/security/src/core/password/password-algorithms.js +397 -0
  201. package/dist/cjs/mods/security/src/core/password/password-algorithms.js.map +1 -0
  202. package/dist/cjs/mods/security/src/core/password/password-core.js +294 -0
  203. package/dist/cjs/mods/security/src/core/password/password-core.js.map +1 -0
  204. package/dist/cjs/mods/security/src/core/password/password-generator.js +365 -0
  205. package/dist/cjs/mods/security/src/core/password/password-generator.js.map +1 -0
  206. package/dist/cjs/mods/security/src/core/password/password-migration.js +237 -0
  207. package/dist/cjs/mods/security/src/core/password/password-migration.js.map +1 -0
  208. package/dist/cjs/mods/security/src/core/password/password-security.js +534 -0
  209. package/dist/cjs/mods/security/src/core/password/password-security.js.map +1 -0
  210. package/dist/cjs/mods/security/src/core/password/password-types.js +39 -0
  211. package/dist/cjs/mods/security/src/core/password/password-types.js.map +1 -0
  212. package/dist/cjs/mods/security/src/core/password/password-utils.js +651 -0
  213. package/dist/cjs/mods/security/src/core/password/password-utils.js.map +1 -0
  214. package/dist/cjs/mods/security/src/core/password/swlist.js +1122 -0
  215. package/dist/cjs/mods/security/src/core/password/swlist.js.map +1 -0
  216. package/dist/cjs/mods/security/src/core/random/random-core.js +328 -0
  217. package/dist/cjs/mods/security/src/core/random/random-core.js.map +1 -0
  218. package/dist/cjs/mods/security/src/core/random/random-crypto.js +339 -0
  219. package/dist/cjs/mods/security/src/core/random/random-crypto.js.map +1 -0
  220. package/dist/cjs/mods/security/src/core/random/random-entropy.js +388 -0
  221. package/dist/cjs/mods/security/src/core/random/random-entropy.js.map +1 -0
  222. package/dist/cjs/mods/security/src/core/random/random-generators.js +344 -0
  223. package/dist/cjs/mods/security/src/core/random/random-generators.js.map +1 -0
  224. package/dist/cjs/mods/security/src/core/random/random-sources.js +426 -0
  225. package/dist/cjs/mods/security/src/core/random/random-sources.js.map +1 -0
  226. package/dist/cjs/mods/security/src/core/random/random-tokens.js +309 -0
  227. package/dist/cjs/mods/security/src/core/random/random-tokens.js.map +1 -0
  228. package/dist/cjs/mods/security/src/core/random/random-types.js +36 -0
  229. package/dist/cjs/mods/security/src/core/random/random-types.js.map +1 -0
  230. package/dist/cjs/mods/security/src/core/validators.js +200 -0
  231. package/dist/cjs/mods/security/src/core/validators.js.map +1 -0
  232. package/dist/cjs/mods/security/src/helpers/Uint8Array.js +335 -0
  233. package/dist/cjs/mods/security/src/helpers/Uint8Array.js.map +1 -0
  234. package/dist/cjs/mods/security/src/helpers/createEnu.js +27 -0
  235. package/dist/cjs/mods/security/src/helpers/createEnu.js.map +1 -0
  236. package/dist/cjs/mods/security/src/index.js +417 -0
  237. package/dist/cjs/mods/security/src/index.js.map +1 -0
  238. package/dist/cjs/mods/security/src/types/global.js +51 -0
  239. package/dist/cjs/mods/security/src/types/global.js.map +1 -0
  240. package/dist/cjs/mods/security/src/types/secure-mem.type.js +100 -0
  241. package/dist/cjs/mods/security/src/types/secure-mem.type.js.map +1 -0
  242. package/dist/cjs/mods/security/src/types/secure-memory.js +20 -0
  243. package/dist/cjs/mods/security/src/types/secure-memory.js.map +1 -0
  244. package/dist/cjs/mods/security/src/types.js +63 -0
  245. package/dist/cjs/mods/security/src/types.js.map +1 -0
  246. package/dist/cjs/mods/security/src/utils/CryptoAlgorithmUtils.js +71 -0
  247. package/dist/cjs/mods/security/src/utils/CryptoAlgorithmUtils.js.map +1 -0
  248. package/dist/cjs/mods/security/src/utils/constants.js +111 -0
  249. package/dist/cjs/mods/security/src/utils/constants.js.map +1 -0
  250. package/dist/cjs/mods/security/src/utils/dataConverter.js +74 -0
  251. package/dist/cjs/mods/security/src/utils/dataConverter.js.map +1 -0
  252. package/dist/cjs/mods/security/src/utils/encoding.js +290 -0
  253. package/dist/cjs/mods/security/src/utils/encoding.js.map +1 -0
  254. package/dist/cjs/mods/security/src/utils/errorHandler.js +140 -0
  255. package/dist/cjs/mods/security/src/utils/errorHandler.js.map +1 -0
  256. package/dist/cjs/mods/security/src/utils/memory/config-manager.js +282 -0
  257. package/dist/cjs/mods/security/src/utils/memory/config-manager.js.map +1 -0
  258. package/dist/cjs/mods/security/src/utils/memory/event-manager.js +277 -0
  259. package/dist/cjs/mods/security/src/utils/memory/event-manager.js.map +1 -0
  260. package/dist/cjs/mods/security/src/utils/memory/index.js +162 -0
  261. package/dist/cjs/mods/security/src/utils/memory/index.js.map +1 -0
  262. package/dist/cjs/mods/security/src/utils/memory/memory-manager.js +888 -0
  263. package/dist/cjs/mods/security/src/utils/memory/memory-manager.js.map +1 -0
  264. package/dist/cjs/mods/security/src/utils/memory/memory-pool.js +356 -0
  265. package/dist/cjs/mods/security/src/utils/memory/memory-pool.js.map +1 -0
  266. package/dist/cjs/mods/security/src/utils/memory/reference-tracker.js +376 -0
  267. package/dist/cjs/mods/security/src/utils/memory/reference-tracker.js.map +1 -0
  268. package/dist/cjs/mods/security/src/utils/memory/types.js +56 -0
  269. package/dist/cjs/mods/security/src/utils/memory/types.js.map +1 -0
  270. package/dist/cjs/mods/security/src/utils/patterns.js +127 -0
  271. package/dist/cjs/mods/security/src/utils/patterns.js.map +1 -0
  272. package/dist/cjs/mods/security/src/utils/performanceMonitor.js +249 -0
  273. package/dist/cjs/mods/security/src/utils/performanceMonitor.js.map +1 -0
  274. package/dist/cjs/mods/security/src/utils/stats.js +182 -0
  275. package/dist/cjs/mods/security/src/utils/stats.js.map +1 -0
  276. package/dist/cjs/security-middleware.js +15 -15
  277. package/dist/cjs/server/components/fastapi/UltraFastRequestProcessor.js +1 -1
  278. package/dist/cjs/server/components/fastapi/console/ConsoleInterceptor.js +23 -23
  279. package/dist/cjs/server/components/fastapi/middlewares/MiddlewareAPI.js +1 -1
  280. package/dist/cjs/server/optimization/RequestPreCompiler.js +1 -1
  281. package/dist/cjs/server/plugins/PluginRegistry.js +1 -1
  282. package/dist/cjs/server/plugins/core/CachePlugin.js +7 -7
  283. package/dist/cjs/server/plugins/core/PerformancePlugin.js +2 -2
  284. package/dist/cjs/server/plugins/core/SecurityPlugin.js +10 -10
  285. package/dist/cjs/smart-routes.js +1 -1
  286. package/dist/esm/ServerFactory.js +1 -1
  287. package/dist/esm/cache/SecureCacheAdapter.js +2 -2
  288. package/dist/esm/cluster/cluster-manager.js +1 -1
  289. package/dist/esm/cluster/index.js +30 -30
  290. package/dist/esm/cluster/modules/AutoScaler.js +2 -2
  291. package/dist/esm/cluster/modules/ClusterPersistenceManager.js +3 -3
  292. package/dist/esm/cluster/modules/HealthMonitor.js +2 -2
  293. package/dist/esm/cluster/modules/IPCManager.js +2 -2
  294. package/dist/esm/cluster/modules/MetricsCollector.js +1 -1
  295. package/dist/esm/cluster/modules/WorkerManager.js +2 -2
  296. package/dist/esm/encryption/EncryptionService.js +12 -12
  297. package/dist/esm/encryption/EncryptionService.js.map +1 -1
  298. package/dist/esm/index.js +1 -1
  299. package/dist/esm/middleware/safe-json-middleware.js +1 -1
  300. package/dist/esm/mods/security/src/algorithms/hash-algorithms.js +705 -0
  301. package/dist/esm/mods/security/src/algorithms/hash-algorithms.js.map +1 -0
  302. package/dist/esm/mods/security/src/algorithms/registry.js +81 -0
  303. package/dist/esm/mods/security/src/algorithms/registry.js.map +1 -0
  304. package/dist/esm/mods/security/src/components/attestation.js +1059 -0
  305. package/dist/esm/mods/security/src/components/attestation.js.map +1 -0
  306. package/dist/esm/mods/security/src/components/cache/FastLRU.js +320 -0
  307. package/dist/esm/mods/security/src/components/cache/FastLRU.js.map +1 -0
  308. package/dist/esm/mods/security/src/components/cache/UFSIMC.js +1109 -0
  309. package/dist/esm/mods/security/src/components/cache/UFSIMC.js.map +1 -0
  310. package/dist/esm/mods/security/src/components/cache/cacheSys.js +622 -0
  311. package/dist/esm/mods/security/src/components/cache/cacheSys.js.map +1 -0
  312. package/dist/esm/mods/security/src/components/cache/cacheSys.utils.js +111 -0
  313. package/dist/esm/mods/security/src/components/cache/cacheSys.utils.js.map +1 -0
  314. package/dist/esm/mods/security/src/components/cache/config/cache.config.js +36 -0
  315. package/dist/esm/mods/security/src/components/cache/config/cache.config.js.map +1 -0
  316. package/dist/esm/mods/security/src/components/cache/index.js +449 -0
  317. package/dist/esm/mods/security/src/components/cache/index.js.map +1 -0
  318. package/dist/esm/mods/security/src/components/cache/useCache.js +240 -0
  319. package/dist/esm/mods/security/src/components/cache/useCache.js.map +1 -0
  320. package/dist/esm/mods/security/src/components/canary-tokens.js +346 -0
  321. package/dist/esm/mods/security/src/components/canary-tokens.js.map +1 -0
  322. package/dist/esm/mods/security/src/components/entropy-augmentation.js +476 -0
  323. package/dist/esm/mods/security/src/components/entropy-augmentation.js.map +1 -0
  324. package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js +336 -0
  325. package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-allocator.js.map +1 -0
  326. package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js +534 -0
  327. package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-cache.js.map +1 -0
  328. package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js +629 -0
  329. package/dist/esm/mods/security/src/components/fortified-function/UFA/ultra-fast-engine.js.map +1 -0
  330. package/dist/esm/mods/security/src/components/fortified-function/const/exec.const.js +11 -0
  331. package/dist/esm/mods/security/src/components/fortified-function/const/exec.const.js.map +1 -0
  332. package/dist/esm/mods/security/src/components/fortified-function/core/fortified-config.js +351 -0
  333. package/dist/esm/mods/security/src/components/fortified-function/core/fortified-config.js.map +1 -0
  334. package/dist/esm/mods/security/src/components/fortified-function/core/fortified-function-core.js +518 -0
  335. package/dist/esm/mods/security/src/components/fortified-function/core/fortified-function-core.js.map +1 -0
  336. package/dist/esm/mods/security/src/components/fortified-function/core/fortified-logger.js +243 -0
  337. package/dist/esm/mods/security/src/components/fortified-function/core/fortified-logger.js.map +1 -0
  338. package/dist/esm/mods/security/src/components/fortified-function/core/mods/api-manager.js +187 -0
  339. package/dist/esm/mods/security/src/components/fortified-function/core/mods/api-manager.js.map +1 -0
  340. package/dist/esm/mods/security/src/components/fortified-function/core/mods/cache-manager.js +105 -0
  341. package/dist/esm/mods/security/src/components/fortified-function/core/mods/cache-manager.js.map +1 -0
  342. package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-context.js +103 -0
  343. package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-context.js.map +1 -0
  344. package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-engine.js +125 -0
  345. package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-engine.js.map +1 -0
  346. package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-router.js +91 -0
  347. package/dist/esm/mods/security/src/components/fortified-function/core/mods/execution-router.js.map +1 -0
  348. package/dist/esm/mods/security/src/components/fortified-function/core/mods/memory-manager.js +145 -0
  349. package/dist/esm/mods/security/src/components/fortified-function/core/mods/memory-manager.js.map +1 -0
  350. package/dist/esm/mods/security/src/components/fortified-function/core/mods/security-manager.js +100 -0
  351. package/dist/esm/mods/security/src/components/fortified-function/core/mods/security-manager.js.map +1 -0
  352. package/dist/esm/mods/security/src/components/fortified-function/core/mods/stats-manager.js +157 -0
  353. package/dist/esm/mods/security/src/components/fortified-function/core/mods/stats-manager.js.map +1 -0
  354. package/dist/esm/mods/security/src/components/fortified-function/core/mods/timing-manager.js +123 -0
  355. package/dist/esm/mods/security/src/components/fortified-function/core/mods/timing-manager.js.map +1 -0
  356. package/dist/esm/mods/security/src/components/fortified-function/engines/analytics-engine.js +368 -0
  357. package/dist/esm/mods/security/src/components/fortified-function/engines/analytics-engine.js.map +1 -0
  358. package/dist/esm/mods/security/src/components/fortified-function/engines/execution-engine.js +400 -0
  359. package/dist/esm/mods/security/src/components/fortified-function/engines/execution-engine.js.map +1 -0
  360. package/dist/esm/mods/security/src/components/fortified-function/index.js +165 -0
  361. package/dist/esm/mods/security/src/components/fortified-function/index.js.map +1 -0
  362. package/dist/esm/mods/security/src/components/fortified-function/performance/performance-monitor.js +238 -0
  363. package/dist/esm/mods/security/src/components/fortified-function/performance/performance-monitor.js.map +1 -0
  364. package/dist/esm/mods/security/src/components/fortified-function/performance/performance-timer.js +186 -0
  365. package/dist/esm/mods/security/src/components/fortified-function/performance/performance-timer.js.map +1 -0
  366. package/dist/esm/mods/security/src/components/fortified-function/security/security-handler.js +251 -0
  367. package/dist/esm/mods/security/src/components/fortified-function/security/security-handler.js.map +1 -0
  368. package/dist/esm/mods/security/src/components/fortified-function/serializer/safe-serializer.js +344 -0
  369. package/dist/esm/mods/security/src/components/fortified-function/serializer/safe-serializer.js.map +1 -0
  370. package/dist/esm/mods/security/src/components/fortified-function/smart-cache.js +691 -0
  371. package/dist/esm/mods/security/src/components/fortified-function/smart-cache.js.map +1 -0
  372. package/dist/esm/mods/security/src/components/fortified-function/types/types.js +14 -0
  373. package/dist/esm/mods/security/src/components/fortified-function/types/types.js.map +1 -0
  374. package/dist/esm/mods/security/src/components/fortified-function/utils/utils.js +66 -0
  375. package/dist/esm/mods/security/src/components/fortified-function/utils/utils.js.map +1 -0
  376. package/dist/esm/mods/security/src/components/memory-hard.js +919 -0
  377. package/dist/esm/mods/security/src/components/memory-hard.js.map +1 -0
  378. package/dist/esm/mods/security/src/components/post-quantum.js +316 -0
  379. package/dist/esm/mods/security/src/components/post-quantum.js.map +1 -0
  380. package/dist/esm/mods/security/src/components/runtime-verification.js +643 -0
  381. package/dist/esm/mods/security/src/components/runtime-verification.js.map +1 -0
  382. package/dist/esm/mods/security/src/components/secure-array/core/secure-array-core.js +1570 -0
  383. package/dist/esm/mods/security/src/components/secure-array/core/secure-array-core.js.map +1 -0
  384. package/dist/esm/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js +328 -0
  385. package/dist/esm/mods/security/src/components/secure-array/crypto/ArrayCryptoHandler.js.map +1 -0
  386. package/dist/esm/mods/security/src/components/secure-array/events/event-manager.js +268 -0
  387. package/dist/esm/mods/security/src/components/secure-array/events/event-manager.js.map +1 -0
  388. package/dist/esm/mods/security/src/components/secure-array/index.js +61 -0
  389. package/dist/esm/mods/security/src/components/secure-array/index.js.map +1 -0
  390. package/dist/esm/mods/security/src/components/secure-array/metadata/metadata-manager.js +329 -0
  391. package/dist/esm/mods/security/src/components/secure-array/metadata/metadata-manager.js.map +1 -0
  392. package/dist/esm/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js +388 -0
  393. package/dist/esm/mods/security/src/components/secure-array/serialization/ArraySerializationHandler.js.map +1 -0
  394. package/dist/esm/mods/security/src/components/secure-array/types/index.js +84 -0
  395. package/dist/esm/mods/security/src/components/secure-array/types/index.js.map +1 -0
  396. package/dist/esm/mods/security/src/components/secure-array/utils/id-generator.js +78 -0
  397. package/dist/esm/mods/security/src/components/secure-array/utils/id-generator.js.map +1 -0
  398. package/dist/esm/mods/security/src/components/secure-array/utils/validation.js +273 -0
  399. package/dist/esm/mods/security/src/components/secure-array/utils/validation.js.map +1 -0
  400. package/dist/esm/mods/security/src/components/secure-memory.js +884 -0
  401. package/dist/esm/mods/security/src/components/secure-memory.js.map +1 -0
  402. package/dist/esm/mods/security/src/components/secure-object/core/secure-object-core.js +1603 -0
  403. package/dist/esm/mods/security/src/components/secure-object/core/secure-object-core.js.map +1 -0
  404. package/dist/esm/mods/security/src/components/secure-object/encryption/crypto-handler.js +360 -0
  405. package/dist/esm/mods/security/src/components/secure-object/encryption/crypto-handler.js.map +1 -0
  406. package/dist/esm/mods/security/src/components/secure-object/encryption/sensitive-keys.js +203 -0
  407. package/dist/esm/mods/security/src/components/secure-object/encryption/sensitive-keys.js.map +1 -0
  408. package/dist/esm/mods/security/src/components/secure-object/events/event-manager.js +195 -0
  409. package/dist/esm/mods/security/src/components/secure-object/events/event-manager.js.map +1 -0
  410. package/dist/esm/mods/security/src/components/secure-object/index.js +63 -0
  411. package/dist/esm/mods/security/src/components/secure-object/index.js.map +1 -0
  412. package/dist/esm/mods/security/src/components/secure-object/metadata/metadata-manager.js +181 -0
  413. package/dist/esm/mods/security/src/components/secure-object/metadata/metadata-manager.js.map +1 -0
  414. package/dist/esm/mods/security/src/components/secure-object/serialization/serialization-handler.js +195 -0
  415. package/dist/esm/mods/security/src/components/secure-object/serialization/serialization-handler.js.map +1 -0
  416. package/dist/esm/mods/security/src/components/secure-object/utils/id-generator.js +62 -0
  417. package/dist/esm/mods/security/src/components/secure-object/utils/id-generator.js.map +1 -0
  418. package/dist/esm/mods/security/src/components/secure-object/utils/validation.js +237 -0
  419. package/dist/esm/mods/security/src/components/secure-object/utils/validation.js.map +1 -0
  420. package/dist/esm/mods/security/src/components/secure-serialization.js +769 -0
  421. package/dist/esm/mods/security/src/components/secure-serialization.js.map +1 -0
  422. package/dist/esm/mods/security/src/components/secure-string/advanced/entropy-analyzer.js +306 -0
  423. package/dist/esm/mods/security/src/components/secure-string/advanced/entropy-analyzer.js.map +1 -0
  424. package/dist/esm/mods/security/src/components/secure-string/advanced/performance-monitor.js +333 -0
  425. package/dist/esm/mods/security/src/components/secure-string/advanced/performance-monitor.js.map +1 -0
  426. package/dist/esm/mods/security/src/components/secure-string/advanced/quantum-safe.js +243 -0
  427. package/dist/esm/mods/security/src/components/secure-string/advanced/quantum-safe.js.map +1 -0
  428. package/dist/esm/mods/security/src/components/secure-string/buffer/buffer-manager.js +203 -0
  429. package/dist/esm/mods/security/src/components/secure-string/buffer/buffer-manager.js.map +1 -0
  430. package/dist/esm/mods/security/src/components/secure-string/core/secure-string-core.js +786 -0
  431. package/dist/esm/mods/security/src/components/secure-string/core/secure-string-core.js.map +1 -0
  432. package/dist/esm/mods/security/src/components/secure-string/crypto/crypto-operations.js +298 -0
  433. package/dist/esm/mods/security/src/components/secure-string/crypto/crypto-operations.js.map +1 -0
  434. package/dist/esm/mods/security/src/components/secure-string/operations/comparison-operations.js +219 -0
  435. package/dist/esm/mods/security/src/components/secure-string/operations/comparison-operations.js.map +1 -0
  436. package/dist/esm/mods/security/src/components/secure-string/operations/string-operations.js +232 -0
  437. package/dist/esm/mods/security/src/components/secure-string/operations/string-operations.js.map +1 -0
  438. package/dist/esm/mods/security/src/components/secure-string/types/index.js +37 -0
  439. package/dist/esm/mods/security/src/components/secure-string/types/index.js.map +1 -0
  440. package/dist/esm/mods/security/src/components/secure-string/validation/string-validator.js +332 -0
  441. package/dist/esm/mods/security/src/components/secure-string/validation/string-validator.js.map +1 -0
  442. package/dist/esm/mods/security/src/components/side-channel.js +142 -0
  443. package/dist/esm/mods/security/src/components/side-channel.js.map +1 -0
  444. package/dist/esm/mods/security/src/components/tamper-evident-logging.js +389 -0
  445. package/dist/esm/mods/security/src/components/tamper-evident-logging.js.map +1 -0
  446. package/dist/esm/mods/security/src/const/buffer.const.js +13 -0
  447. package/dist/esm/mods/security/src/const/buffer.const.js.map +1 -0
  448. package/dist/esm/mods/security/src/core/crypto.js +720 -0
  449. package/dist/esm/mods/security/src/core/crypto.js.map +1 -0
  450. package/dist/esm/mods/security/src/core/hash/hash-advanced.js +367 -0
  451. package/dist/esm/mods/security/src/core/hash/hash-advanced.js.map +1 -0
  452. package/dist/esm/mods/security/src/core/hash/hash-core.js +355 -0
  453. package/dist/esm/mods/security/src/core/hash/hash-core.js.map +1 -0
  454. package/dist/esm/mods/security/src/core/hash/hash-entropy.js +286 -0
  455. package/dist/esm/mods/security/src/core/hash/hash-entropy.js.map +1 -0
  456. package/dist/esm/mods/security/src/core/hash/hash-security.js +351 -0
  457. package/dist/esm/mods/security/src/core/hash/hash-security.js.map +1 -0
  458. package/dist/esm/mods/security/src/core/hash/hash-types.js +16 -0
  459. package/dist/esm/mods/security/src/core/hash/hash-types.js.map +1 -0
  460. package/dist/esm/mods/security/src/core/hash/hash-utils.js +307 -0
  461. package/dist/esm/mods/security/src/core/hash/hash-utils.js.map +1 -0
  462. package/dist/esm/mods/security/src/core/hash/hash-validator.js +310 -0
  463. package/dist/esm/mods/security/src/core/hash/hash-validator.js.map +1 -0
  464. package/dist/esm/mods/security/src/core/hash.js +9 -0
  465. package/dist/esm/mods/security/src/core/hash.js.map +1 -0
  466. package/dist/esm/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js +133 -0
  467. package/dist/esm/mods/security/src/core/keys/algorithms/mods/Argon2Algo.js.map +1 -0
  468. package/dist/esm/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js +272 -0
  469. package/dist/esm/mods/security/src/core/keys/algorithms/mods/PBKDF2Algo.js.map +1 -0
  470. package/dist/esm/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js +296 -0
  471. package/dist/esm/mods/security/src/core/keys/algorithms/mods/ScryptAlgo.js.map +1 -0
  472. package/dist/esm/mods/security/src/core/keys/keys-core.js +199 -0
  473. package/dist/esm/mods/security/src/core/keys/keys-core.js.map +1 -0
  474. package/dist/esm/mods/security/src/core/keys/keys-logger.js +231 -0
  475. package/dist/esm/mods/security/src/core/keys/keys-logger.js.map +1 -0
  476. package/dist/esm/mods/security/src/core/keys/keys-types.js +63 -0
  477. package/dist/esm/mods/security/src/core/keys/keys-types.js.map +1 -0
  478. package/dist/esm/mods/security/src/core/keys/keys-utils.js +316 -0
  479. package/dist/esm/mods/security/src/core/keys/keys-utils.js.map +1 -0
  480. package/dist/esm/mods/security/src/core/keys.js +134 -0
  481. package/dist/esm/mods/security/src/core/keys.js.map +1 -0
  482. package/dist/esm/mods/security/src/core/password/index.js +110 -0
  483. package/dist/esm/mods/security/src/core/password/index.js.map +1 -0
  484. package/dist/esm/mods/security/src/core/password/password-algorithms.js +395 -0
  485. package/dist/esm/mods/security/src/core/password/password-algorithms.js.map +1 -0
  486. package/dist/esm/mods/security/src/core/password/password-core.js +292 -0
  487. package/dist/esm/mods/security/src/core/password/password-core.js.map +1 -0
  488. package/dist/esm/mods/security/src/core/password/password-generator.js +363 -0
  489. package/dist/esm/mods/security/src/core/password/password-generator.js.map +1 -0
  490. package/dist/esm/mods/security/src/core/password/password-migration.js +235 -0
  491. package/dist/esm/mods/security/src/core/password/password-migration.js.map +1 -0
  492. package/dist/esm/mods/security/src/core/password/password-security.js +532 -0
  493. package/dist/esm/mods/security/src/core/password/password-security.js.map +1 -0
  494. package/dist/esm/mods/security/src/core/password/password-types.js +34 -0
  495. package/dist/esm/mods/security/src/core/password/password-types.js.map +1 -0
  496. package/dist/esm/mods/security/src/core/password/password-utils.js +630 -0
  497. package/dist/esm/mods/security/src/core/password/password-utils.js.map +1 -0
  498. package/dist/esm/mods/security/src/core/password/swlist.js +1120 -0
  499. package/dist/esm/mods/security/src/core/password/swlist.js.map +1 -0
  500. package/dist/esm/mods/security/src/core/random/random-core.js +326 -0
  501. package/dist/esm/mods/security/src/core/random/random-core.js.map +1 -0
  502. package/dist/esm/mods/security/src/core/random/random-crypto.js +337 -0
  503. package/dist/esm/mods/security/src/core/random/random-crypto.js.map +1 -0
  504. package/dist/esm/mods/security/src/core/random/random-entropy.js +367 -0
  505. package/dist/esm/mods/security/src/core/random/random-entropy.js.map +1 -0
  506. package/dist/esm/mods/security/src/core/random/random-generators.js +323 -0
  507. package/dist/esm/mods/security/src/core/random/random-generators.js.map +1 -0
  508. package/dist/esm/mods/security/src/core/random/random-sources.js +405 -0
  509. package/dist/esm/mods/security/src/core/random/random-sources.js.map +1 -0
  510. package/dist/esm/mods/security/src/core/random/random-tokens.js +307 -0
  511. package/dist/esm/mods/security/src/core/random/random-tokens.js.map +1 -0
  512. package/dist/esm/mods/security/src/core/random/random-types.js +27 -0
  513. package/dist/esm/mods/security/src/core/random/random-types.js.map +1 -0
  514. package/dist/esm/mods/security/src/core/validators.js +198 -0
  515. package/dist/esm/mods/security/src/core/validators.js.map +1 -0
  516. package/dist/esm/mods/security/src/helpers/Uint8Array.js +333 -0
  517. package/dist/esm/mods/security/src/helpers/Uint8Array.js.map +1 -0
  518. package/dist/esm/mods/security/src/helpers/createEnu.js +25 -0
  519. package/dist/esm/mods/security/src/helpers/createEnu.js.map +1 -0
  520. package/dist/esm/mods/security/src/index.js +373 -0
  521. package/dist/esm/mods/security/src/index.js.map +1 -0
  522. package/dist/esm/mods/security/src/types/global.js +49 -0
  523. package/dist/esm/mods/security/src/types/global.js.map +1 -0
  524. package/dist/esm/mods/security/src/types/secure-mem.type.js +96 -0
  525. package/dist/esm/mods/security/src/types/secure-mem.type.js.map +1 -0
  526. package/dist/esm/mods/security/src/types/secure-memory.js +20 -0
  527. package/dist/esm/mods/security/src/types/secure-memory.js.map +1 -0
  528. package/dist/esm/mods/security/src/types.js +63 -0
  529. package/dist/esm/mods/security/src/types.js.map +1 -0
  530. package/dist/esm/mods/security/src/utils/CryptoAlgorithmUtils.js +69 -0
  531. package/dist/esm/mods/security/src/utils/CryptoAlgorithmUtils.js.map +1 -0
  532. package/dist/esm/mods/security/src/utils/constants.js +105 -0
  533. package/dist/esm/mods/security/src/utils/constants.js.map +1 -0
  534. package/dist/esm/mods/security/src/utils/dataConverter.js +72 -0
  535. package/dist/esm/mods/security/src/utils/dataConverter.js.map +1 -0
  536. package/dist/esm/mods/security/src/utils/encoding.js +279 -0
  537. package/dist/esm/mods/security/src/utils/encoding.js.map +1 -0
  538. package/dist/esm/mods/security/src/utils/errorHandler.js +137 -0
  539. package/dist/esm/mods/security/src/utils/errorHandler.js.map +1 -0
  540. package/dist/esm/mods/security/src/utils/memory/config-manager.js +280 -0
  541. package/dist/esm/mods/security/src/utils/memory/config-manager.js.map +1 -0
  542. package/dist/esm/mods/security/src/utils/memory/event-manager.js +275 -0
  543. package/dist/esm/mods/security/src/utils/memory/event-manager.js.map +1 -0
  544. package/dist/esm/mods/security/src/utils/memory/index.js +141 -0
  545. package/dist/esm/mods/security/src/utils/memory/index.js.map +1 -0
  546. package/dist/esm/mods/security/src/utils/memory/memory-manager.js +886 -0
  547. package/dist/esm/mods/security/src/utils/memory/memory-manager.js.map +1 -0
  548. package/dist/esm/mods/security/src/utils/memory/memory-pool.js +354 -0
  549. package/dist/esm/mods/security/src/utils/memory/memory-pool.js.map +1 -0
  550. package/dist/esm/mods/security/src/utils/memory/reference-tracker.js +374 -0
  551. package/dist/esm/mods/security/src/utils/memory/reference-tracker.js.map +1 -0
  552. package/dist/esm/mods/security/src/utils/memory/types.js +56 -0
  553. package/dist/esm/mods/security/src/utils/memory/types.js.map +1 -0
  554. package/dist/esm/mods/security/src/utils/patterns.js +124 -0
  555. package/dist/esm/mods/security/src/utils/patterns.js.map +1 -0
  556. package/dist/esm/mods/security/src/utils/performanceMonitor.js +246 -0
  557. package/dist/esm/mods/security/src/utils/performanceMonitor.js.map +1 -0
  558. package/dist/esm/mods/security/src/utils/stats.js +180 -0
  559. package/dist/esm/mods/security/src/utils/stats.js.map +1 -0
  560. package/dist/esm/security-middleware.js +15 -15
  561. package/dist/esm/server/components/fastapi/UltraFastRequestProcessor.js +1 -1
  562. package/dist/esm/server/components/fastapi/console/ConsoleInterceptor.js +23 -23
  563. package/dist/esm/server/components/fastapi/middlewares/MiddlewareAPI.js +1 -1
  564. package/dist/esm/server/optimization/RequestPreCompiler.js +1 -1
  565. package/dist/esm/server/plugins/PluginRegistry.js +1 -1
  566. package/dist/esm/server/plugins/core/CachePlugin.js +7 -7
  567. package/dist/esm/server/plugins/core/PerformancePlugin.js +2 -2
  568. package/dist/esm/server/plugins/core/SecurityPlugin.js +10 -10
  569. package/dist/esm/smart-routes.js +1 -1
  570. 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, "&amp;")
1570
+ .replace(/</g, "&lt;")
1571
+ .replace(/>/g, "&gt;")
1572
+ .replace(/"/g, "&quot;")
1573
+ .replace(/'/g, "&#39;");
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