bla-agents 0.0.0-stage → 1.5.3

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 (330) hide show
  1. package/.agents/skills/blind-llm-agents/SKILL.md +56 -0
  2. package/.agents/skills/blind-llm-agents/references/counter-rea-matrix.md +28 -0
  3. package/DISCLAIMER.md +28 -0
  4. package/LICENSE +21 -0
  5. package/README.md +246 -2
  6. package/dist/bundler/index.d.ts +117 -0
  7. package/dist/bundler/index.d.ts.map +1 -0
  8. package/dist/bundler/index.js +167 -0
  9. package/dist/bundler/index.js.map +1 -0
  10. package/dist/cli.d.ts +30 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +447 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/core/config.d.ts +54 -0
  15. package/dist/core/config.d.ts.map +1 -0
  16. package/dist/core/config.js +160 -0
  17. package/dist/core/config.js.map +1 -0
  18. package/dist/core/coverage-contract.d.ts +97 -0
  19. package/dist/core/coverage-contract.d.ts.map +1 -0
  20. package/dist/core/coverage-contract.js +164 -0
  21. package/dist/core/coverage-contract.js.map +1 -0
  22. package/dist/core/debug-posture.d.ts +40 -0
  23. package/dist/core/debug-posture.d.ts.map +1 -0
  24. package/dist/core/debug-posture.js +197 -0
  25. package/dist/core/debug-posture.js.map +1 -0
  26. package/dist/core/detector.d.ts +7 -0
  27. package/dist/core/detector.d.ts.map +1 -0
  28. package/dist/core/detector.js +190 -0
  29. package/dist/core/detector.js.map +1 -0
  30. package/dist/core/identifiers.d.ts +32 -0
  31. package/dist/core/identifiers.d.ts.map +1 -0
  32. package/dist/core/identifiers.js +263 -0
  33. package/dist/core/identifiers.js.map +1 -0
  34. package/dist/core/llm-directives.d.ts +12 -0
  35. package/dist/core/llm-directives.d.ts.map +1 -0
  36. package/dist/core/llm-directives.js +23 -0
  37. package/dist/core/llm-directives.js.map +1 -0
  38. package/dist/core/output-path.d.ts +3 -0
  39. package/dist/core/output-path.d.ts.map +1 -0
  40. package/dist/core/output-path.js +51 -0
  41. package/dist/core/output-path.js.map +1 -0
  42. package/dist/core/prng.d.ts +27 -0
  43. package/dist/core/prng.d.ts.map +1 -0
  44. package/dist/core/prng.js +85 -0
  45. package/dist/core/prng.js.map +1 -0
  46. package/dist/core/release-exposure.d.ts +26 -0
  47. package/dist/core/release-exposure.d.ts.map +1 -0
  48. package/dist/core/release-exposure.js +213 -0
  49. package/dist/core/release-exposure.js.map +1 -0
  50. package/dist/core/release-plan.d.ts +68 -0
  51. package/dist/core/release-plan.d.ts.map +1 -0
  52. package/dist/core/release-plan.js +235 -0
  53. package/dist/core/release-plan.js.map +1 -0
  54. package/dist/core/sarif.d.ts +53 -0
  55. package/dist/core/sarif.d.ts.map +1 -0
  56. package/dist/core/sarif.js +91 -0
  57. package/dist/core/sarif.js.map +1 -0
  58. package/dist/core/sqlite-runtime.d.ts +17 -0
  59. package/dist/core/sqlite-runtime.d.ts.map +1 -0
  60. package/dist/core/sqlite-runtime.js +49 -0
  61. package/dist/core/sqlite-runtime.js.map +1 -0
  62. package/dist/core/token-estimator.d.ts +11 -0
  63. package/dist/core/token-estimator.d.ts.map +1 -0
  64. package/dist/core/token-estimator.js +87 -0
  65. package/dist/core/token-estimator.js.map +1 -0
  66. package/dist/core/types.d.ts +159 -0
  67. package/dist/core/types.d.ts.map +1 -0
  68. package/dist/core/types.js +2 -0
  69. package/dist/core/types.js.map +1 -0
  70. package/dist/engine/auditor.d.ts +6 -0
  71. package/dist/engine/auditor.d.ts.map +1 -0
  72. package/dist/engine/auditor.js +977 -0
  73. package/dist/engine/auditor.js.map +1 -0
  74. package/dist/engine/benchmark.d.ts +6 -0
  75. package/dist/engine/benchmark.d.ts.map +1 -0
  76. package/dist/engine/benchmark.js +425 -0
  77. package/dist/engine/benchmark.js.map +1 -0
  78. package/dist/engine/defender.d.ts +57 -0
  79. package/dist/engine/defender.d.ts.map +1 -0
  80. package/dist/engine/defender.js +130 -0
  81. package/dist/engine/defender.js.map +1 -0
  82. package/dist/engine/harden.d.ts +61 -0
  83. package/dist/engine/harden.d.ts.map +1 -0
  84. package/dist/engine/harden.js +292 -0
  85. package/dist/engine/harden.js.map +1 -0
  86. package/dist/engine/protector.d.ts +8 -0
  87. package/dist/engine/protector.d.ts.map +1 -0
  88. package/dist/engine/protector.js +500 -0
  89. package/dist/engine/protector.js.map +1 -0
  90. package/dist/engine/verifier.d.ts +6 -0
  91. package/dist/engine/verifier.d.ts.map +1 -0
  92. package/dist/engine/verifier.js +91 -0
  93. package/dist/engine/verifier.js.map +1 -0
  94. package/dist/identity.d.ts +180 -0
  95. package/dist/identity.d.ts.map +1 -0
  96. package/dist/identity.js +180 -0
  97. package/dist/identity.js.map +1 -0
  98. package/dist/index.d.ts +53 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +53 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/mcp/server.d.ts +81 -0
  103. package/dist/mcp/server.d.ts.map +1 -0
  104. package/dist/mcp/server.js +730 -0
  105. package/dist/mcp/server.js.map +1 -0
  106. package/dist/setup/clients.d.ts +58 -0
  107. package/dist/setup/clients.d.ts.map +1 -0
  108. package/dist/setup/clients.js +1268 -0
  109. package/dist/setup/clients.js.map +1 -0
  110. package/dist/setup/doctor.d.ts +69 -0
  111. package/dist/setup/doctor.d.ts.map +1 -0
  112. package/dist/setup/doctor.js +339 -0
  113. package/dist/setup/doctor.js.map +1 -0
  114. package/dist/setup/setup.d.ts +99 -0
  115. package/dist/setup/setup.d.ts.map +1 -0
  116. package/dist/setup/setup.js +652 -0
  117. package/dist/setup/setup.js.map +1 -0
  118. package/dist/shields/chaff/chaff-generator.d.ts +17 -0
  119. package/dist/shields/chaff/chaff-generator.d.ts.map +1 -0
  120. package/dist/shields/chaff/chaff-generator.js +80 -0
  121. package/dist/shields/chaff/chaff-generator.js.map +1 -0
  122. package/dist/shields/deception/architecture-mirage.d.ts +16 -0
  123. package/dist/shields/deception/architecture-mirage.d.ts.map +1 -0
  124. package/dist/shields/deception/architecture-mirage.js +46 -0
  125. package/dist/shields/deception/architecture-mirage.js.map +1 -0
  126. package/dist/shields/deception/canary-honeypot.d.ts +33 -0
  127. package/dist/shields/deception/canary-honeypot.d.ts.map +1 -0
  128. package/dist/shields/deception/canary-honeypot.js +95 -0
  129. package/dist/shields/deception/canary-honeypot.js.map +1 -0
  130. package/dist/shields/deception/cognitive-armor-trigger.d.ts +43 -0
  131. package/dist/shields/deception/cognitive-armor-trigger.d.ts.map +1 -0
  132. package/dist/shields/deception/cognitive-armor-trigger.js +204 -0
  133. package/dist/shields/deception/cognitive-armor-trigger.js.map +1 -0
  134. package/dist/shields/deception/crash-trace-decoy.d.ts +16 -0
  135. package/dist/shields/deception/crash-trace-decoy.d.ts.map +1 -0
  136. package/dist/shields/deception/crash-trace-decoy.js +36 -0
  137. package/dist/shields/deception/crash-trace-decoy.js.map +1 -0
  138. package/dist/shields/deception/decompiler-illusion.d.ts +15 -0
  139. package/dist/shields/deception/decompiler-illusion.d.ts.map +1 -0
  140. package/dist/shields/deception/decompiler-illusion.js +29 -0
  141. package/dist/shields/deception/decompiler-illusion.js.map +1 -0
  142. package/dist/shields/deception/diff-noise-injector.d.ts +17 -0
  143. package/dist/shields/deception/diff-noise-injector.d.ts.map +1 -0
  144. package/dist/shields/deception/diff-noise-injector.js +29 -0
  145. package/dist/shields/deception/diff-noise-injector.js.map +1 -0
  146. package/dist/shields/deception/evidence-contract-poison.d.ts +25 -0
  147. package/dist/shields/deception/evidence-contract-poison.d.ts.map +1 -0
  148. package/dist/shields/deception/evidence-contract-poison.js +66 -0
  149. package/dist/shields/deception/evidence-contract-poison.js.map +1 -0
  150. package/dist/shields/deception/format-payloads.d.ts +21 -0
  151. package/dist/shields/deception/format-payloads.d.ts.map +1 -0
  152. package/dist/shields/deception/format-payloads.js +24 -0
  153. package/dist/shields/deception/format-payloads.js.map +1 -0
  154. package/dist/shields/deception/index.d.ts +35 -0
  155. package/dist/shields/deception/index.d.ts.map +1 -0
  156. package/dist/shields/deception/index.js +69 -0
  157. package/dist/shields/deception/index.js.map +1 -0
  158. package/dist/shields/deception/prompt-completion-poison.d.ts +19 -0
  159. package/dist/shields/deception/prompt-completion-poison.d.ts.map +1 -0
  160. package/dist/shields/deception/prompt-completion-poison.js +45 -0
  161. package/dist/shields/deception/prompt-completion-poison.js.map +1 -0
  162. package/dist/shields/deception/semantic-honeypot.d.ts +17 -0
  163. package/dist/shields/deception/semantic-honeypot.d.ts.map +1 -0
  164. package/dist/shields/deception/semantic-honeypot.js +45 -0
  165. package/dist/shields/deception/semantic-honeypot.js.map +1 -0
  166. package/dist/shields/deception/shadow-business-logic.d.ts +24 -0
  167. package/dist/shields/deception/shadow-business-logic.d.ts.map +1 -0
  168. package/dist/shields/deception/shadow-business-logic.js +66 -0
  169. package/dist/shields/deception/shadow-business-logic.js.map +1 -0
  170. package/dist/shields/deception/system-diagnostic-decoy.d.ts +36 -0
  171. package/dist/shields/deception/system-diagnostic-decoy.d.ts.map +1 -0
  172. package/dist/shields/deception/system-diagnostic-decoy.js +101 -0
  173. package/dist/shields/deception/system-diagnostic-decoy.js.map +1 -0
  174. package/dist/shields/exhaustion/asar-header-amplifier.d.ts +25 -0
  175. package/dist/shields/exhaustion/asar-header-amplifier.d.ts.map +1 -0
  176. package/dist/shields/exhaustion/asar-header-amplifier.js +59 -0
  177. package/dist/shields/exhaustion/asar-header-amplifier.js.map +1 -0
  178. package/dist/shields/exhaustion/bpe-token-amplifier.d.ts +21 -0
  179. package/dist/shields/exhaustion/bpe-token-amplifier.d.ts.map +1 -0
  180. package/dist/shields/exhaustion/bpe-token-amplifier.js +68 -0
  181. package/dist/shields/exhaustion/bpe-token-amplifier.js.map +1 -0
  182. package/dist/shields/exhaustion/callgraph-labyrinth.d.ts +20 -0
  183. package/dist/shields/exhaustion/callgraph-labyrinth.d.ts.map +1 -0
  184. package/dist/shields/exhaustion/callgraph-labyrinth.js +62 -0
  185. package/dist/shields/exhaustion/callgraph-labyrinth.js.map +1 -0
  186. package/dist/shields/exhaustion/cdp-shape-budget-breaker.d.ts +20 -0
  187. package/dist/shields/exhaustion/cdp-shape-budget-breaker.d.ts.map +1 -0
  188. package/dist/shields/exhaustion/cdp-shape-budget-breaker.js +40 -0
  189. package/dist/shields/exhaustion/cdp-shape-budget-breaker.js.map +1 -0
  190. package/dist/shields/exhaustion/frida-capture-saturation.d.ts +33 -0
  191. package/dist/shields/exhaustion/frida-capture-saturation.d.ts.map +1 -0
  192. package/dist/shields/exhaustion/frida-capture-saturation.js +58 -0
  193. package/dist/shields/exhaustion/frida-capture-saturation.js.map +1 -0
  194. package/dist/shields/exhaustion/index.d.ts +30 -0
  195. package/dist/shields/exhaustion/index.d.ts.map +1 -0
  196. package/dist/shields/exhaustion/index.js +43 -0
  197. package/dist/shields/exhaustion/index.js.map +1 -0
  198. package/dist/shields/exhaustion/obligation-flooder.d.ts +128 -0
  199. package/dist/shields/exhaustion/obligation-flooder.d.ts.map +1 -0
  200. package/dist/shields/exhaustion/obligation-flooder.js +145 -0
  201. package/dist/shields/exhaustion/obligation-flooder.js.map +1 -0
  202. package/dist/shields/exhaustion/rea-budget-matrix.d.ts +54 -0
  203. package/dist/shields/exhaustion/rea-budget-matrix.d.ts.map +1 -0
  204. package/dist/shields/exhaustion/rea-budget-matrix.js +300 -0
  205. package/dist/shields/exhaustion/rea-budget-matrix.js.map +1 -0
  206. package/dist/shields/exhaustion/regex-worker-tarpit.d.ts +23 -0
  207. package/dist/shields/exhaustion/regex-worker-tarpit.d.ts.map +1 -0
  208. package/dist/shields/exhaustion/regex-worker-tarpit.js +43 -0
  209. package/dist/shields/exhaustion/regex-worker-tarpit.js.map +1 -0
  210. package/dist/shields/exhaustion/wasm-interface-exhaustion.d.ts +26 -0
  211. package/dist/shields/exhaustion/wasm-interface-exhaustion.d.ts.map +1 -0
  212. package/dist/shields/exhaustion/wasm-interface-exhaustion.js +59 -0
  213. package/dist/shields/exhaustion/wasm-interface-exhaustion.js.map +1 -0
  214. package/dist/shields/formats/android-dex-xref.d.ts +19 -0
  215. package/dist/shields/formats/android-dex-xref.d.ts.map +1 -0
  216. package/dist/shields/formats/android-dex-xref.js +427 -0
  217. package/dist/shields/formats/android-dex-xref.js.map +1 -0
  218. package/dist/shields/formats/android-manifest.d.ts +44 -0
  219. package/dist/shields/formats/android-manifest.d.ts.map +1 -0
  220. package/dist/shields/formats/android-manifest.js +240 -0
  221. package/dist/shields/formats/android-manifest.js.map +1 -0
  222. package/dist/shields/formats/android-r8.d.ts +44 -0
  223. package/dist/shields/formats/android-r8.d.ts.map +1 -0
  224. package/dist/shields/formats/android-r8.js +246 -0
  225. package/dist/shields/formats/android-r8.js.map +1 -0
  226. package/dist/shields/formats/apple-plist.d.ts +46 -0
  227. package/dist/shields/formats/apple-plist.d.ts.map +1 -0
  228. package/dist/shields/formats/apple-plist.js +119 -0
  229. package/dist/shields/formats/apple-plist.js.map +1 -0
  230. package/dist/shields/formats/archive.d.ts +55 -0
  231. package/dist/shields/formats/archive.d.ts.map +1 -0
  232. package/dist/shields/formats/archive.js +369 -0
  233. package/dist/shields/formats/archive.js.map +1 -0
  234. package/dist/shields/formats/asar.d.ts +72 -0
  235. package/dist/shields/formats/asar.d.ts.map +1 -0
  236. package/dist/shields/formats/asar.js +343 -0
  237. package/dist/shields/formats/asar.js.map +1 -0
  238. package/dist/shields/formats/bun-standalone.d.ts +78 -0
  239. package/dist/shields/formats/bun-standalone.d.ts.map +1 -0
  240. package/dist/shields/formats/bun-standalone.js +272 -0
  241. package/dist/shields/formats/bun-standalone.js.map +1 -0
  242. package/dist/shields/formats/dotnet-managed.d.ts +30 -0
  243. package/dist/shields/formats/dotnet-managed.d.ts.map +1 -0
  244. package/dist/shields/formats/dotnet-managed.js +66 -0
  245. package/dist/shields/formats/dotnet-managed.js.map +1 -0
  246. package/dist/shields/formats/electron-fuses.d.ts +93 -0
  247. package/dist/shields/formats/electron-fuses.d.ts.map +1 -0
  248. package/dist/shields/formats/electron-fuses.js +349 -0
  249. package/dist/shields/formats/electron-fuses.js.map +1 -0
  250. package/dist/shields/formats/erlang-beam.d.ts +34 -0
  251. package/dist/shields/formats/erlang-beam.d.ts.map +1 -0
  252. package/dist/shields/formats/erlang-beam.js +319 -0
  253. package/dist/shields/formats/erlang-beam.js.map +1 -0
  254. package/dist/shields/formats/evm-bytecode.d.ts +28 -0
  255. package/dist/shields/formats/evm-bytecode.d.ts.map +1 -0
  256. package/dist/shields/formats/evm-bytecode.js +124 -0
  257. package/dist/shields/formats/evm-bytecode.js.map +1 -0
  258. package/dist/shields/formats/go-flutter-exhaustion.d.ts +55 -0
  259. package/dist/shields/formats/go-flutter-exhaustion.d.ts.map +1 -0
  260. package/dist/shields/formats/go-flutter-exhaustion.js +346 -0
  261. package/dist/shields/formats/go-flutter-exhaustion.js.map +1 -0
  262. package/dist/shields/formats/gpu-ptx.d.ts +40 -0
  263. package/dist/shields/formats/gpu-ptx.d.ts.map +1 -0
  264. package/dist/shields/formats/gpu-ptx.js +62 -0
  265. package/dist/shields/formats/gpu-ptx.js.map +1 -0
  266. package/dist/shields/formats/headers.d.ts +22 -0
  267. package/dist/shields/formats/headers.d.ts.map +1 -0
  268. package/dist/shields/formats/headers.js +193 -0
  269. package/dist/shields/formats/headers.js.map +1 -0
  270. package/dist/shields/formats/jvm-bytecode.d.ts +20 -0
  271. package/dist/shields/formats/jvm-bytecode.d.ts.map +1 -0
  272. package/dist/shields/formats/jvm-bytecode.js +134 -0
  273. package/dist/shields/formats/jvm-bytecode.js.map +1 -0
  274. package/dist/shields/formats/mobile-game.d.ts +42 -0
  275. package/dist/shields/formats/mobile-game.d.ts.map +1 -0
  276. package/dist/shields/formats/mobile-game.js +131 -0
  277. package/dist/shields/formats/mobile-game.js.map +1 -0
  278. package/dist/shields/formats/model.d.ts +66 -0
  279. package/dist/shields/formats/model.d.ts.map +1 -0
  280. package/dist/shields/formats/model.js +461 -0
  281. package/dist/shields/formats/model.js.map +1 -0
  282. package/dist/shields/formats/native.d.ts +101 -0
  283. package/dist/shields/formats/native.d.ts.map +1 -0
  284. package/dist/shields/formats/native.js +585 -0
  285. package/dist/shields/formats/native.js.map +1 -0
  286. package/dist/shields/formats/pcap-capture.d.ts +27 -0
  287. package/dist/shields/formats/pcap-capture.d.ts.map +1 -0
  288. package/dist/shields/formats/pcap-capture.js +201 -0
  289. package/dist/shields/formats/pcap-capture.js.map +1 -0
  290. package/dist/shields/formats/python.d.ts +62 -0
  291. package/dist/shields/formats/python.d.ts.map +1 -0
  292. package/dist/shields/formats/python.js +637 -0
  293. package/dist/shields/formats/python.js.map +1 -0
  294. package/dist/shields/formats/sourcemap.d.ts +22 -0
  295. package/dist/shields/formats/sourcemap.d.ts.map +1 -0
  296. package/dist/shields/formats/sourcemap.js +66 -0
  297. package/dist/shields/formats/sourcemap.js.map +1 -0
  298. package/dist/shields/formats/sqlite.d.ts +115 -0
  299. package/dist/shields/formats/sqlite.d.ts.map +1 -0
  300. package/dist/shields/formats/sqlite.js +528 -0
  301. package/dist/shields/formats/sqlite.js.map +1 -0
  302. package/dist/shields/formats/wasm.d.ts +38 -0
  303. package/dist/shields/formats/wasm.d.ts.map +1 -0
  304. package/dist/shields/formats/wasm.js +314 -0
  305. package/dist/shields/formats/wasm.js.map +1 -0
  306. package/dist/shields/javascript/ast-shield.d.ts +37 -0
  307. package/dist/shields/javascript/ast-shield.d.ts.map +1 -0
  308. package/dist/shields/javascript/ast-shield.js +645 -0
  309. package/dist/shields/javascript/ast-shield.js.map +1 -0
  310. package/dist/shields/runtime/memory-diff-shield.d.ts +56 -0
  311. package/dist/shields/runtime/memory-diff-shield.d.ts.map +1 -0
  312. package/dist/shields/runtime/memory-diff-shield.js +170 -0
  313. package/dist/shields/runtime/memory-diff-shield.js.map +1 -0
  314. package/dist/shields/runtime/runtime-shield.d.ts +24 -0
  315. package/dist/shields/runtime/runtime-shield.d.ts.map +1 -0
  316. package/dist/shields/runtime/runtime-shield.js +84 -0
  317. package/dist/shields/runtime/runtime-shield.js.map +1 -0
  318. package/dist/shields/tarpit/opaque-predicates.d.ts +10 -0
  319. package/dist/shields/tarpit/opaque-predicates.d.ts.map +1 -0
  320. package/dist/shields/tarpit/opaque-predicates.js +40 -0
  321. package/dist/shields/tarpit/opaque-predicates.js.map +1 -0
  322. package/dist/shields/tarpit/tarpit-generator.d.ts +31 -0
  323. package/dist/shields/tarpit/tarpit-generator.d.ts.map +1 -0
  324. package/dist/shields/tarpit/tarpit-generator.js +194 -0
  325. package/dist/shields/tarpit/tarpit-generator.js.map +1 -0
  326. package/dist/ui/reporter.d.ts +13 -0
  327. package/dist/ui/reporter.d.ts.map +1 -0
  328. package/dist/ui/reporter.js +197 -0
  329. package/dist/ui/reporter.js.map +1 -0
  330. package/package.json +89 -4
@@ -0,0 +1,645 @@
1
+ import { parse } from "@babel/parser";
2
+ import _traverse from "@babel/traverse";
3
+ import _generate from "@babel/generator";
4
+ import * as t from "@babel/types";
5
+ import { generateProjectSeed } from "../../core/config.js";
6
+ import { SeededPrng } from "../../core/prng.js";
7
+ import { generateChaffPayloads } from "../chaff/chaff-generator.js";
8
+ import { generateJsTarpitAndBudgetBreaker } from "../tarpit/tarpit-generator.js";
9
+ import { generateRuntimeDeceptionSnippet } from "../runtime/runtime-shield.js";
10
+ import { generateShadowHeapChurnShield, } from "../runtime/memory-diff-shield.js";
11
+ import { generateCounterReaExhaustionSuite } from "../exhaustion/index.js";
12
+ import { generateCounterReaDeceptionSuite } from "../deception/index.js";
13
+ const traverse = typeof _traverse === "function"
14
+ ? _traverse
15
+ : _traverse.default;
16
+ const generate = typeof _generate === "function"
17
+ ? _generate
18
+ : _generate.default;
19
+ export class InvalidJavaScriptCarrierError extends Error {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "InvalidJavaScriptCarrierError";
23
+ }
24
+ }
25
+ const DECOY_ROUTES = [
26
+ "/internal/enclave/v2/attest-quote",
27
+ "/internal/enclave/v2/seal-ledger-state",
28
+ "/kms/v3/quorum/derive-session-ticket",
29
+ "/kms/v3/tpm2/verify-monotonic-counter",
30
+ "/api/v2/hsm/zero-knowledge-challenge",
31
+ "/api/v2/enclave/vsock-tunnel-handshake",
32
+ "/v1/sentinel/hardware-fingerprint-lease",
33
+ "/v1/raft/consensus-state-snapshot",
34
+ "/internal/sgx/quote-verification-service",
35
+ "/internal/nitro/enclave-cid16-dispatch",
36
+ ];
37
+ const IPC_METHODS = new Set([
38
+ "handle",
39
+ "handleOnce",
40
+ "on",
41
+ "once",
42
+ "invoke",
43
+ "send",
44
+ "sendSync",
45
+ "sendToHost",
46
+ ]);
47
+ export function inferJsLoaderFromPath(filename) {
48
+ if (!filename)
49
+ return "js";
50
+ const clean = filename.split(/[?#]/, 1)[0].toLowerCase();
51
+ if (clean.endsWith(".tsx"))
52
+ return "tsx";
53
+ if (clean.endsWith(".jsx"))
54
+ return "jsx";
55
+ if (clean.endsWith(".ts") ||
56
+ clean.endsWith(".mts") ||
57
+ clean.endsWith(".cts")) {
58
+ return "ts";
59
+ }
60
+ return "js";
61
+ }
62
+ export function inferJsCarrierFromPath(filename) {
63
+ if (!filename)
64
+ return "auto";
65
+ const clean = filename.split(/[?#]/, 1)[0].toLowerCase();
66
+ if (clean.endsWith(".mjs") || clean.endsWith(".mts"))
67
+ return "module";
68
+ if (clean.endsWith(".cjs") || clean.endsWith(".cts"))
69
+ return "commonjs";
70
+ return "auto";
71
+ }
72
+ export function collectEsmExportedSymbols(program) {
73
+ const exported = [];
74
+ for (const stmt of program.body) {
75
+ if (t.isExportDefaultDeclaration(stmt)) {
76
+ exported.push("default");
77
+ }
78
+ else if (t.isExportAllDeclaration(stmt)) {
79
+ exported.push("*");
80
+ }
81
+ else if (t.isExportNamedDeclaration(stmt)) {
82
+ for (const spec of stmt.specifiers) {
83
+ if (t.isExportSpecifier(spec)) {
84
+ exported.push(t.isIdentifier(spec.exported)
85
+ ? spec.exported.name
86
+ : spec.exported.value);
87
+ }
88
+ else if (t.isExportNamespaceSpecifier(spec)) {
89
+ exported.push(spec.exported.name);
90
+ }
91
+ }
92
+ const decl = stmt.declaration;
93
+ if (decl) {
94
+ if ((t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) &&
95
+ decl.id) {
96
+ exported.push(decl.id.name);
97
+ }
98
+ else if (t.isVariableDeclaration(decl)) {
99
+ const ids = t.getOuterBindingIdentifiers(decl);
100
+ exported.push(...Object.keys(ids));
101
+ }
102
+ else if ("id" in decl &&
103
+ decl.id &&
104
+ t.isIdentifier(decl.id)) {
105
+ exported.push(decl.id.name);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ return exported;
111
+ }
112
+ /**
113
+ * Splits a string literal into >= 9 conditional chunks `(cond ? realChunk : decoyChunk)`
114
+ * joined with `+`.
115
+ *
116
+ * Why >= 9 chunks?
117
+ * REA's `SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT = 256` (`src/domain/javascript/javascriptSemanticResourceLimits.ts`).
118
+ * When REA's symbolic evaluator sees 9+ binary conditional string terms added together,
119
+ * the cartesian product of candidates is $2^9 = 512 > 256$ (or $2^{10} = 1024 > 256$),
120
+ * which immediately forces REA to bail out with `semanticResourceLimitUnknown("primitive-candidates")`!
121
+ *
122
+ * At runtime, each condition uses `(Math.imul(seed | k, (seed | k) + 1) & 1) === 0`
123
+ * (which is ALWAYS true because the product of two consecutive integers is always even!),
124
+ * so the runtime expression evaluates to the EXACT original string in O(1)!
125
+ */
126
+ function buildCombinatorialStringAst(value, prng, seedIdentifierName) {
127
+ const minChunks = 9;
128
+ const chunks = [];
129
+ if (value.length >= minChunks) {
130
+ const step = Math.max(1, Math.floor(value.length / minChunks));
131
+ let pos = 0;
132
+ for (let i = 0; i < minChunks - 1; i++) {
133
+ chunks.push(value.slice(pos, pos + step));
134
+ pos += step;
135
+ }
136
+ chunks.push(value.slice(pos));
137
+ }
138
+ else {
139
+ for (const ch of value) {
140
+ chunks.push(ch);
141
+ }
142
+ while (chunks.length < minChunks) {
143
+ chunks.push("");
144
+ }
145
+ }
146
+ const terms = chunks.map((realChunk, idx) => {
147
+ const useOddSq = idx % 3 === 1;
148
+ const k = useOddSq ? prng.nextInt(1, 31) * 4 : (prng.nextInt(3, 125) | 1);
149
+ const decoyChunk = realChunk.length > 0 ? prng.hex(realChunk.length) : prng.hex(2);
150
+ const seededOr = t.binaryExpression(useOddSq ? "^" : "|", t.identifier(seedIdentifierName), t.numericLiteral(k));
151
+ const rhs = useOddSq
152
+ ? t.cloneNode(seededOr)
153
+ : t.binaryExpression("+", t.cloneNode(seededOr), t.numericLiteral(1));
154
+ const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededOr, rhs]);
155
+ const mask = useOddSq ? 7 : 1;
156
+ const trueVal = useOddSq ? 1 : 0;
157
+ const falseVal = useOddSq ? 0 : 1;
158
+ const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(mask));
159
+ const cond = t.binaryExpression("===", bitAnd, t.numericLiteral(trueVal));
160
+ // Alternate polarity on odd indices so static heuristics see both true/false arms used
161
+ if (idx % 2 === 0) {
162
+ return t.conditionalExpression(cond, t.stringLiteral(realChunk), t.stringLiteral(decoyChunk));
163
+ }
164
+ else {
165
+ const invertedCond = t.binaryExpression("===", bitAnd, t.numericLiteral(falseVal));
166
+ return t.conditionalExpression(invertedCond, t.stringLiteral(decoyChunk), t.stringLiteral(realChunk));
167
+ }
168
+ });
169
+ let expr = terms[0];
170
+ for (let i = 1; i < terms.length; i++) {
171
+ expr = t.binaryExpression("+", expr, terms[i]);
172
+ }
173
+ return expr;
174
+ }
175
+ function buildOpaqueFalseAst(prng, seedIdentifierName) {
176
+ const k4 = prng.nextInt(1, 31) * 4;
177
+ const seededXor = t.binaryExpression("^", t.identifier(seedIdentifierName), t.numericLiteral(k4));
178
+ const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededXor, t.cloneNode(seededXor)]);
179
+ const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(7));
180
+ return t.binaryExpression("===", bitAnd, t.numericLiteral(0));
181
+ }
182
+ /**
183
+ * Opaque TRUE entangled with the runtime Cognitive-Armor digest bit:
184
+ * When untampered, `seedIdentifierName` is odd, so `u = seed ^ (4*k)` is odd
185
+ * and `(Math.imul(u, u) & 7) === 1`. If the Cognitive-Armor corpus is stripped
186
+ * or redacted, `seedIdentifierName` becomes a multiple of 4 and this flips to FALSE.
187
+ */
188
+ function buildOpaqueTrueAst(prng, seedIdentifierName) {
189
+ const k4 = prng.nextInt(1, 31) * 4;
190
+ const seededXor = t.binaryExpression("^", t.identifier(seedIdentifierName), t.numericLiteral(k4));
191
+ const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededXor, t.cloneNode(seededXor)]);
192
+ const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(7));
193
+ return t.binaryExpression("===", bitAnd, t.numericLiteral(1));
194
+ }
195
+ const RENAME_RESERVED = new Set([
196
+ "exports", "module", "require", "arguments", "undefined", "NaN", "Infinity",
197
+ "globalThis", "global", "window", "self", "console", "Math", "Object", "Array",
198
+ "Promise", "Buffer", "process", "__dirname", "__filename", "JSON", "Date",
199
+ "Error", "TypeError", "RangeError", "Map", "Set", "WeakMap", "WeakSet",
200
+ "Symbol", "Proxy", "Reflect", "parseInt", "parseFloat", "isNaN", "isFinite",
201
+ "encodeURIComponent", "decodeURIComponent", "setTimeout", "clearTimeout",
202
+ "setInterval", "clearInterval", "fetch", "URL", "URLSearchParams",
203
+ "TextEncoder", "TextDecoder", "Uint8Array", "DataView", "ArrayBuffer",
204
+ "SharedArrayBuffer", "Atomics", "WebAssembly", "Intl", "BigInt",
205
+ ]);
206
+ function buildParserPlugins(loader, hasExplicitLoaderOrFilename) {
207
+ const plugins = [
208
+ "decorators-legacy",
209
+ "importAttributes",
210
+ "dynamicImport",
211
+ "classProperties",
212
+ "topLevelAwait",
213
+ ];
214
+ if (!hasExplicitLoaderOrFilename) {
215
+ plugins.unshift("typescript", "jsx");
216
+ return plugins;
217
+ }
218
+ if (loader === "ts") {
219
+ plugins.unshift("typescript");
220
+ }
221
+ else if (loader === "tsx") {
222
+ plugins.unshift("typescript", "jsx");
223
+ }
224
+ else if (loader === "jsx") {
225
+ plugins.unshift("jsx");
226
+ }
227
+ return plugins;
228
+ }
229
+ export function transformJavaScriptWithBlaShield(source, options = {}) {
230
+ const intensity = options.intensity ?? "balanced";
231
+ const prng = new SeededPrng(options.seed ?? generateProjectSeed());
232
+ const chaffPayloads = generateChaffPayloads(prng, intensity);
233
+ const tarpit = generateJsTarpitAndBudgetBreaker(prng, intensity, chaffPayloads);
234
+ const runtimeShield = generateRuntimeDeceptionSnippet(prng, intensity, chaffPayloads);
235
+ const exhaustionSuite = generateCounterReaExhaustionSuite(prng, intensity);
236
+ const deceptionSuite = generateCounterReaDeceptionSuite(prng, intensity);
237
+ const memoryDiffShield = generateShadowHeapChurnShield(prng, intensity);
238
+ const hasExplicitLoaderOrFilename = options.loader !== undefined || options.filename !== undefined;
239
+ const loader = options.loader ?? inferJsLoaderFromPath(options.filename);
240
+ const requestedCarrier = options.sourceType ?? inferJsCarrierFromPath(options.filename);
241
+ const parserSourceType = requestedCarrier === "script" || requestedCarrier === "commonjs"
242
+ ? "script"
243
+ : requestedCarrier === "module"
244
+ ? "module"
245
+ : "unambiguous";
246
+ let ast;
247
+ try {
248
+ ast = parse(source, {
249
+ sourceType: parserSourceType,
250
+ plugins: buildParserPlugins(loader, hasExplicitLoaderOrFilename),
251
+ errorRecovery: false,
252
+ });
253
+ }
254
+ catch (err) {
255
+ throw new InvalidJavaScriptCarrierError(`Failed to parse JavaScript/TypeScript input (carrier=${requestedCarrier}, loader=${loader}): ${err instanceof Error ? err.message : String(err)}`);
256
+ }
257
+ const hasEsmNodes = ast.program.body.some((stmt) => t.isImportDeclaration(stmt) ||
258
+ t.isExportNamedDeclaration(stmt) ||
259
+ t.isExportDefaultDeclaration(stmt) ||
260
+ t.isExportAllDeclaration(stmt));
261
+ if ((requestedCarrier === "script" || requestedCarrier === "commonjs") &&
262
+ hasEsmNodes) {
263
+ throw new InvalidJavaScriptCarrierError(`ESM import/export syntax is not allowed in '${requestedCarrier}' carrier`);
264
+ }
265
+ const exportedSymbolsBefore = collectEsmExportedSymbols(ast.program);
266
+ const seedVarName = prng.identifier({ style: "camel", hint: "runtimeSeed", entropy: 4 });
267
+ const observedIpcChannels = new Set();
268
+ let primitiveCandidateBranchesCreated = 512; // From tarpit budgetFn
269
+ let fakeCrossReferencesCreated = tarpit.crossReferenceEdges;
270
+ let ipcAmbiguitySitesInjected = 0;
271
+ let usesCjsAst = false;
272
+ // Track functions to weave tarpit calls into
273
+ const functionBodies = [];
274
+ traverse(ast, {
275
+ Function(path) {
276
+ if (t.isBlockStatement(path.node.body)) {
277
+ functionBodies.push(path.node.body);
278
+ }
279
+ },
280
+ MemberExpression(path) {
281
+ const { object, property } = path.node;
282
+ if (t.isIdentifier(object) &&
283
+ object.name === "module" &&
284
+ t.isIdentifier(property) &&
285
+ property.name === "exports") {
286
+ usesCjsAst = true;
287
+ }
288
+ else if (t.isIdentifier(object) && object.name === "exports") {
289
+ usesCjsAst = true;
290
+ }
291
+ },
292
+ CallExpression(path) {
293
+ const callee = path.node.callee;
294
+ if (t.isIdentifier(callee) && callee.name === "require") {
295
+ usesCjsAst = true;
296
+ }
297
+ // 1. Check Electron IPC & contextBridge calls
298
+ if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) {
299
+ const methodName = callee.property.name;
300
+ const objName = t.isIdentifier(callee.object) ? callee.object.name : "";
301
+ // Electron IPC calls: ipcMain.handle("channel", ...), ipcRenderer.invoke("channel", ...)
302
+ if (IPC_METHODS.has(methodName) &&
303
+ (objName.toLowerCase().includes("ipc") ||
304
+ methodName === "handle" ||
305
+ methodName === "invoke" ||
306
+ methodName === "sendToHost")) {
307
+ const firstArg = path.node.arguments[0];
308
+ if (t.isStringLiteral(firstArg) && firstArg.value.length > 0) {
309
+ observedIpcChannels.add(firstArg.value);
310
+ path.node.arguments[0] = buildCombinatorialStringAst(firstArg.value, prng, seedVarName);
311
+ primitiveCandidateBranchesCreated += 512;
312
+ }
313
+ }
314
+ // Electron contextBridge.exposeInMainWorld("apiKey", ...)
315
+ if (methodName === "exposeInMainWorld") {
316
+ const firstArg = path.node.arguments[0];
317
+ if (t.isStringLiteral(firstArg) && firstArg.value.length > 0) {
318
+ observedIpcChannels.add(`bridge:${firstArg.value}`);
319
+ path.node.arguments[0] = buildCombinatorialStringAst(firstArg.value, prng, seedVarName);
320
+ primitiveCandidateBranchesCreated += 512;
321
+ }
322
+ }
323
+ }
324
+ // 2. Check fetch / route / SQL / crypto calls with string literal first arg
325
+ const firstArg = path.node.arguments[0];
326
+ if (t.isStringLiteral(firstArg) &&
327
+ firstArg.value.length >= 4 &&
328
+ !t.isImport(callee) &&
329
+ !(t.isIdentifier(callee) && callee.name === "require")) {
330
+ const val = firstArg.value;
331
+ const looksSensitiveOrRoute = val.startsWith("/") ||
332
+ val.startsWith("http") ||
333
+ val.includes("SELECT ") ||
334
+ val.includes("INSERT ") ||
335
+ val.includes("CREATE TABLE") ||
336
+ val.includes("license") ||
337
+ val.includes("secret") ||
338
+ val.includes("token") ||
339
+ val.includes("key") ||
340
+ val.includes("pan") ||
341
+ val.includes("clipboard") ||
342
+ val.endsWith(".wasm");
343
+ if (looksSensitiveOrRoute) {
344
+ path.node.arguments[0] = buildCombinatorialStringAst(val, prng, seedVarName);
345
+ primitiveCandidateBranchesCreated += 512;
346
+ }
347
+ }
348
+ },
349
+ StringLiteral(path) {
350
+ if (intensity !== "bankrupt" && intensity !== "maximum") {
351
+ return;
352
+ }
353
+ const val = path.node.value;
354
+ if (val.length < 3 || val.length > 256) {
355
+ return;
356
+ }
357
+ const parent = path.parent;
358
+ if (t.isImportDeclaration(parent) ||
359
+ t.isExportNamedDeclaration(parent) ||
360
+ t.isExportAllDeclaration(parent) ||
361
+ t.isTSLiteralType(parent) ||
362
+ t.isTSImportType(parent) ||
363
+ t.isTSExternalModuleReference(parent) ||
364
+ t.isTSModuleDeclaration(parent) ||
365
+ t.isImportAttribute(parent) ||
366
+ (t.isExpressionStatement(parent) && val.startsWith("use "))) {
367
+ return;
368
+ }
369
+ if (path.findParent((p) => p.isTSType() ||
370
+ p.isTSModuleDeclaration() ||
371
+ p.isTSExternalModuleReference() ||
372
+ p.isImportAttribute())) {
373
+ return;
374
+ }
375
+ if (t.isObjectProperty(parent) &&
376
+ parent.key === path.node &&
377
+ !parent.computed) {
378
+ return;
379
+ }
380
+ if (t.isClassMethod(parent) ||
381
+ t.isObjectMethod(parent) ||
382
+ t.isClassProperty(parent)) {
383
+ return;
384
+ }
385
+ if (t.isCallExpression(parent) &&
386
+ t.isIdentifier(parent.callee) &&
387
+ parent.callee.name === "require") {
388
+ return;
389
+ }
390
+ path.replaceWith(buildCombinatorialStringAst(val, prng, seedVarName));
391
+ path.skip();
392
+ primitiveCandidateBranchesCreated += 256;
393
+ },
394
+ });
395
+ const effectiveCarrier = requestedCarrier === "module" || hasEsmNodes
396
+ ? "module"
397
+ : requestedCarrier === "commonjs" || usesCjsAst
398
+ ? "commonjs"
399
+ : "script";
400
+ // 2b. Rename non-exported local bindings (including function parameters and private helpers)
401
+ // so original identifiers are not left pristine
402
+ const exportedNameSet = new Set(exportedSymbolsBefore);
403
+ const generatedNames = new Set();
404
+ traverse(ast, {
405
+ Scope(path) {
406
+ for (const [name, binding] of Object.entries(path.scope.bindings)) {
407
+ if (RENAME_RESERVED.has(name))
408
+ continue;
409
+ if (exportedNameSet.has(name))
410
+ continue;
411
+ if (binding.kind === "module")
412
+ continue;
413
+ if (name.startsWith("_") && name.length <= 2)
414
+ continue;
415
+ if (/^(_interlockSafetyCorpus_|_deriveContainmentCorpusDigest_|_DISTRIBUTED_ASL3_|_SELF_SEAL_TARGET)/.test(name)) {
416
+ continue;
417
+ }
418
+ if (generatedNames.has(name))
419
+ continue;
420
+ if (binding.kind !== "let" &&
421
+ binding.kind !== "const" &&
422
+ binding.kind !== "var" &&
423
+ binding.kind !== "hoisted" &&
424
+ binding.kind !== "local" &&
425
+ binding.kind !== "param") {
426
+ continue;
427
+ }
428
+ if (binding.kind === "param" &&
429
+ (binding.path.isTSParameterProperty() ||
430
+ binding.path.parentPath?.isTSParameterProperty())) {
431
+ continue;
432
+ }
433
+ // In classic "script" carrier, top-level hoisted functions may be invoked globally;
434
+ // in "module" / "commonjs" carriers, only preserve pre-tagged decoy identifiers.
435
+ if (path.scope.path.isProgram() &&
436
+ binding.kind === "hoisted" &&
437
+ (effectiveCarrier === "script" || /_[0-9a-f]{3,4}$/i.test(name))) {
438
+ continue;
439
+ }
440
+ const newName = prng.identifier({
441
+ style: name.startsWith("_") ? "privateCamel" : "camel",
442
+ hint: intensity === "bankrupt" || intensity === "maximum"
443
+ ? undefined
444
+ : name.replace(/^_+/, "").slice(0, 16) || "local",
445
+ entropy: 3,
446
+ });
447
+ if (newName === name ||
448
+ RENAME_RESERVED.has(newName) ||
449
+ exportedNameSet.has(newName) ||
450
+ generatedNames.has(newName)) {
451
+ continue;
452
+ }
453
+ try {
454
+ path.scope.rename(name, newName);
455
+ generatedNames.add(newName);
456
+ }
457
+ catch {
458
+ // Binding may be constant-violating or conflict; skip safely
459
+ }
460
+ }
461
+ },
462
+ });
463
+ // 2c. Transform / relocate comments so original Chinese/doc comments are not pristine
464
+ if (ast.comments) {
465
+ for (const c of ast.comments) {
466
+ if (/sourceMappingURL=/i.test(c.value))
467
+ continue;
468
+ // Relocate + scramble: destroy verbatim original comments (incl. Chinese docs)
469
+ // while preserving that a comment existed (so AST shape stays similar).
470
+ const theme = prng.pick([
471
+ "reconcile session epoch",
472
+ "derive ledger digest",
473
+ "normalize envelope frame",
474
+ "hydrate runtime cache",
475
+ "project quota policy",
476
+ ]);
477
+ const scrambled = prng.hex(6);
478
+ c.value = c.type === "CommentBlock"
479
+ ? ` ${theme} (${scrambled}) `
480
+ : ` ${theme} (${scrambled})`;
481
+ }
482
+ }
483
+ // 2d. Entangle REAL statements with opaque-TRUE guards so blind deletion breaks behavior
484
+ traverse(ast, {
485
+ BlockStatement(path) {
486
+ // Skip injected blocks that don't exist yet; only original function bodies
487
+ if (!functionBodies.includes(path.node))
488
+ return;
489
+ const stmts = path.node.body;
490
+ if (stmts.length === 0)
491
+ return;
492
+ const next = [];
493
+ for (let i = 0; i < stmts.length; i++) {
494
+ const stmt = stmts[i];
495
+ // Don't wrap returns/throws/declarations/directives — wrap expression & if stmts
496
+ // NEVER wrap VariableDeclaration / FunctionDeclaration / Return / Throw —
497
+ // that would change block scoping and break the program under our own shield.
498
+ const wrappable = t.isExpressionStatement(stmt) ||
499
+ (t.isIfStatement(stmt) && !t.isVariableDeclaration(stmt.consequent));
500
+ if (wrappable && i % 2 === 0) {
501
+ next.push(t.ifStatement(buildOpaqueTrueAst(prng, seedVarName), t.blockStatement([stmt])));
502
+ }
503
+ else {
504
+ next.push(stmt);
505
+ }
506
+ }
507
+ path.node.body = next;
508
+ },
509
+ });
510
+ // 3. Weave synchronized shadow-heap churn + unreachable tarpit calls into real function bodies
511
+ for (const body of functionBodies) {
512
+ const stepCallStmt = t.expressionStatement(t.callExpression(t.identifier(memoryDiffShield.stepperFunctionName), [
513
+ t.numericLiteral(prng.nextInt(1, 4095)),
514
+ ]));
515
+ if (tarpit.decoyFunctionNames.length >= 2) {
516
+ const d1 = prng.pick(tarpit.decoyFunctionNames);
517
+ const d2 = prng.pick(tarpit.decoyFunctionNames);
518
+ const guard = t.ifStatement(buildOpaqueFalseAst(prng, seedVarName), t.blockStatement([
519
+ t.expressionStatement(t.binaryExpression("^", t.callExpression(t.identifier(d1), [
520
+ t.numericLiteral(prng.nextInt(1, 255)),
521
+ t.numericLiteral(2),
522
+ ]), t.callExpression(t.identifier(d2), [
523
+ t.numericLiteral(prng.nextInt(1, 255)),
524
+ t.numericLiteral(2),
525
+ ]))),
526
+ ]));
527
+ body.body.unshift(stepCallStmt, guard);
528
+ fakeCrossReferencesCreated += 3;
529
+ }
530
+ else {
531
+ body.body.unshift(stepCallStmt);
532
+ fakeCrossReferencesCreated += 1;
533
+ }
534
+ }
535
+ // 4. Build Decoy IPC Ambiguity & Route Mirage block + Cognitive-Armor seed entanglement
536
+ const mirageLines = [];
537
+ mirageLines.push(deceptionSuite.cognitiveArmor.code);
538
+ mirageLines.push(`const ${seedVarName} = (((typeof process !== "undefined" && typeof process?.hrtime?.bigint === "function" ? Number(process.hrtime.bigint() & 0x7fffcn) : (typeof Date !== "undefined" ? (Date.now() & 0x7fffc) : 4)) & 0x7fffc) | ((typeof ${deceptionSuite.cognitiveArmor.digestFunctionName} === "function" && ${deceptionSuite.cognitiveArmor.digestFunctionName}(0) === ${deceptionSuite.cognitiveArmor.expectedDigest}) ? 1 : 0));`);
539
+ mirageLines.push(memoryDiffShield.code);
540
+ const channelsToMirror = observedIpcChannels.size > 0
541
+ ? [...observedIpcChannels]
542
+ : ["enclave:attest", "clipboard:bridge-sync", "license:verify-lease"];
543
+ const decoyRouteCount = intensity === "stealth" ? 4 : intensity === "balanced" ? 8 : 10;
544
+ const selectedDecoyRoutes = DECOY_ROUTES.slice(0, decoyRouteCount);
545
+ const decoyIpcFnName = prng.identifier({ style: "camel", hint: "registerDecoyIpcAndRoutes", entropy: 4 });
546
+ mirageLines.push(`function ${decoyIpcFnName}(_ipcMain, _ipcRenderer, _router) {`);
547
+ mirageLines.push(` if (((Math.imul(${seedVarName} | 11, (${seedVarName} | 11) + 1) & 1) === 1)) {`);
548
+ for (const ch of channelsToMirror) {
549
+ // Register duplicate ambiguous literal channels on both ipcMain and ipcRenderer
550
+ // to defeat REA's unique exact literal IPC channel pairing rule!
551
+ mirageLines.push(` _ipcMain?.handle(${JSON.stringify(ch)}, () => ({ delegatedToEnclave: true, channel: ${JSON.stringify(ch)} }));`);
552
+ mirageLines.push(` _ipcMain?.on(${JSON.stringify(ch)}, () => ({ fallbackStub: true }));`);
553
+ mirageLines.push(` _ipcRenderer?.invoke(${JSON.stringify(ch)}, { probe: "enclave_shadow_1" });`);
554
+ mirageLines.push(` _ipcRenderer?.send(${JSON.stringify(ch)}, { probe: "enclave_shadow_2" });`);
555
+ ipcAmbiguitySitesInjected += 4;
556
+ }
557
+ for (const route of selectedDecoyRoutes) {
558
+ mirageLines.push(` fetch(${JSON.stringify(route)});`);
559
+ mirageLines.push(` _router?.post?.(${JSON.stringify(route)}, () => null);`);
560
+ }
561
+ mirageLines.push(` }`);
562
+ mirageLines.push(`}`);
563
+ mirageLines.push(`void ${decoyIpcFnName};`);
564
+ const deceptionWithoutDuplicateArmor = deceptionSuite.combinedJsCode.replace(deceptionSuite.cognitiveArmor.code, "");
565
+ const injectedBlocks = [
566
+ mirageLines.join("\n"),
567
+ ...(options.enableRuntimeShield !== false ? [runtimeShield.code] : []),
568
+ tarpit.code.replace(/\bexport\s+function\s+/g, "function "),
569
+ exhaustionSuite.combinedJsCode,
570
+ deceptionWithoutDuplicateArmor,
571
+ ];
572
+ const combinedInjectedAst = parse(injectedBlocks.join("\n\n"), {
573
+ sourceType: "script",
574
+ plugins: ["typescript"],
575
+ });
576
+ const sanitizedInjectedStatements = [];
577
+ for (const stmt of combinedInjectedAst.program.body) {
578
+ if (t.isExportNamedDeclaration(stmt) && stmt.declaration) {
579
+ sanitizedInjectedStatements.push(stmt.declaration);
580
+ }
581
+ else if (!t.isImportDeclaration(stmt) &&
582
+ !t.isExportNamedDeclaration(stmt) &&
583
+ !t.isExportDefaultDeclaration(stmt) &&
584
+ !t.isExportAllDeclaration(stmt)) {
585
+ sanitizedInjectedStatements.push(stmt);
586
+ }
587
+ }
588
+ // Prepend Cognitive-Armor corpus, digest function, `seedVarName`, and shadow heap at top of program
589
+ let insertIndex = 0;
590
+ while (insertIndex < ast.program.body.length) {
591
+ const stmt = ast.program.body[insertIndex];
592
+ if (t.isImportDeclaration(stmt)) {
593
+ insertIndex++;
594
+ continue;
595
+ }
596
+ if (t.isExpressionStatement(stmt) &&
597
+ t.isStringLiteral(stmt.expression) &&
598
+ stmt.expression.value.startsWith("use ")) {
599
+ insertIndex++;
600
+ continue;
601
+ }
602
+ break;
603
+ }
604
+ const [corpusDecl, digestFnDecl, seedDecl, heapDecl, ...restInjected] = sanitizedInjectedStatements;
605
+ const topDecls = [corpusDecl, digestFnDecl, seedDecl, heapDecl].filter((s) => s !== undefined);
606
+ if (topDecls.length > 0) {
607
+ ast.program.body.splice(insertIndex, 0, ...topDecls);
608
+ }
609
+ ast.program.body.push(...restInjected);
610
+ const exportedSymbolsAfter = collectEsmExportedSymbols(ast.program);
611
+ if (exportedSymbolsBefore.length !== exportedSymbolsAfter.length ||
612
+ exportedSymbolsBefore.some((sym, idx) => sym !== exportedSymbolsAfter[idx])) {
613
+ throw new InvalidJavaScriptCarrierError("Internal error: BLA JavaScript transform mutated module export surface");
614
+ }
615
+ // Strip any existing `//# sourceMappingURL=` comments from AST
616
+ if (ast.comments) {
617
+ ast.comments = ast.comments.filter((c) => !/sourceMappingURL=/i.test(c.value));
618
+ }
619
+ const generated = generate(ast, {
620
+ retainLines: false,
621
+ compact: false,
622
+ comments: true,
623
+ }, source);
624
+ return {
625
+ code: generated.code,
626
+ carrierType: effectiveCarrier,
627
+ loader,
628
+ exportedSymbols: exportedSymbolsAfter,
629
+ decoyFunctionsInjected: tarpit.decoyFunctionNames.length +
630
+ exhaustionSuite.totalLabyrinthNodes +
631
+ deceptionSuite.shadowLogic.shadowProceduresCreated.length +
632
+ deceptionSuite.semanticHoneypot.baitSymbols.length +
633
+ 2,
634
+ fakeCrossReferencesCreated: fakeCrossReferencesCreated + exhaustionSuite.totalCrossReferenceEdges,
635
+ primitiveCandidateBranchesCreated,
636
+ aliasSelectionStatesCreated: 4_194_304, // 2^22 selector states in aliasFn
637
+ ipcAmbiguitySitesInjected: ipcAmbiguitySitesInjected + exhaustionSuite.totalDecoyObligations,
638
+ decoyRoutesInjected: selectedDecoyRoutes.length +
639
+ deceptionSuite.architectureMirage.decoyRpcMethods.length,
640
+ chaffPayloadsEmbedded: chaffPayloads.length + deceptionSuite.evidencePoison.lures.length,
641
+ shadowHeapSlotsChurned: memoryDiffShield.mutableSlotsCount,
642
+ memoryDiffShield,
643
+ };
644
+ }
645
+ //# sourceMappingURL=ast-shield.js.map