unpeek 1.7.2 → 1.8.2

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 (63) hide show
  1. package/dist/ast/index.cjs +2278 -386
  2. package/dist/ast/index.cjs.map +1 -1
  3. package/dist/ast/index.d.cts +69 -1
  4. package/dist/ast/index.d.ts +69 -1
  5. package/dist/ast/index.js +2266 -385
  6. package/dist/ast/index.js.map +1 -1
  7. package/dist/browser.cjs +2265 -393
  8. package/dist/browser.cjs.map +1 -1
  9. package/dist/browser.d.cts +2 -1
  10. package/dist/browser.d.ts +2 -1
  11. package/dist/browser.js +2260 -388
  12. package/dist/browser.js.map +1 -1
  13. package/dist/bundler/unplugin.cjs +2259 -385
  14. package/dist/bundler/unplugin.cjs.map +1 -1
  15. package/dist/bundler/unplugin.js +2258 -384
  16. package/dist/bundler/unplugin.js.map +1 -1
  17. package/dist/cli/index.cjs +2292 -396
  18. package/dist/cli/index.cjs.map +1 -1
  19. package/dist/cli/index.js +2292 -396
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/cli/protect.cjs +2284 -391
  22. package/dist/cli/protect.cjs.map +1 -1
  23. package/dist/cli/protect.js +2285 -392
  24. package/dist/cli/protect.js.map +1 -1
  25. package/dist/esbuild.cjs +2259 -385
  26. package/dist/esbuild.cjs.map +1 -1
  27. package/dist/esbuild.d.cts +1 -1
  28. package/dist/esbuild.d.ts +1 -1
  29. package/dist/esbuild.js +2258 -384
  30. package/dist/esbuild.js.map +1 -1
  31. package/dist/index.cjs +2309 -411
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +2 -1
  34. package/dist/index.d.ts +2 -1
  35. package/dist/index.js +2296 -398
  36. package/dist/index.js.map +1 -1
  37. package/dist/rollup.cjs +2259 -385
  38. package/dist/rollup.cjs.map +1 -1
  39. package/dist/rollup.d.cts +1 -1
  40. package/dist/rollup.d.ts +1 -1
  41. package/dist/rollup.js +2258 -384
  42. package/dist/rollup.js.map +1 -1
  43. package/dist/runtime/index.cjs +366 -8
  44. package/dist/runtime/index.cjs.map +1 -1
  45. package/dist/runtime/index.d.cts +11 -3
  46. package/dist/runtime/index.d.ts +11 -3
  47. package/dist/runtime/index.js +364 -8
  48. package/dist/runtime/index.js.map +1 -1
  49. package/dist/{types-D-lVfaDU.d.cts → types-CQHprSVk.d.cts} +10 -0
  50. package/dist/{types-D-lVfaDU.d.ts → types-CQHprSVk.d.ts} +10 -0
  51. package/dist/vite.cjs +2259 -385
  52. package/dist/vite.cjs.map +1 -1
  53. package/dist/vite.d.cts +1 -1
  54. package/dist/vite.d.ts +1 -1
  55. package/dist/vite.js +2258 -384
  56. package/dist/vite.js.map +1 -1
  57. package/dist/webpack.cjs +2259 -385
  58. package/dist/webpack.cjs.map +1 -1
  59. package/dist/webpack.d.cts +1 -1
  60. package/dist/webpack.d.ts +1 -1
  61. package/dist/webpack.js +2258 -384
  62. package/dist/webpack.js.map +1 -1
  63. package/package.json +1 -1
package/dist/webpack.js CHANGED
@@ -1,9 +1,6 @@
1
1
  // src/bundler/unplugin.ts
2
2
  import { createUnplugin } from "unplugin";
3
3
 
4
- // src/ast/index.ts
5
- import { generate } from "astring";
6
-
7
4
  // src/ast/hot-path-detector.ts
8
5
  import * as acorn from "acorn";
9
6
  import * as walk from "acorn-walk";
@@ -18,7 +15,12 @@ var ARRAY_HOF_METHODS = /* @__PURE__ */ new Set([
18
15
  "some",
19
16
  "every"
20
17
  ]);
21
- var UI_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
18
+ var ANIMATION_FRAME_CALLS = /* @__PURE__ */ new Set([
19
+ "requestAnimationFrame",
20
+ "cancelAnimationFrame",
21
+ "useFrame"
22
+ ]);
23
+ var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
22
24
  "useState",
23
25
  "useEffect",
24
26
  "useMemo",
@@ -29,9 +31,7 @@ var UI_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
29
31
  "jsxs",
30
32
  "_jsx",
31
33
  "_jsxs",
32
- "createElement",
33
- "requestAnimationFrame",
34
- "cancelAnimationFrame"
34
+ "createElement"
35
35
  ]);
36
36
  var FUNCTION_NODE_TYPES = /* @__PURE__ */ new Set([
37
37
  "FunctionDeclaration",
@@ -66,8 +66,13 @@ function getFunctionLabel(node, ancestors) {
66
66
  if (parent.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
67
67
  return parent.id.name;
68
68
  }
69
- if (parent.type === "Property" && parent.key?.type === "Identifier") {
70
- return parent.key.name;
69
+ if (parent.type === "Property") {
70
+ if (parent.key?.type === "Identifier") {
71
+ return parent.key.name;
72
+ }
73
+ if (parent.key?.type === "Literal" && typeof parent.key.value === "string") {
74
+ return parent.key.value;
75
+ }
71
76
  }
72
77
  if (parent.type === "MethodDefinition" && parent.key?.type === "Identifier") {
73
78
  return parent.key.name;
@@ -81,6 +86,9 @@ function getFunctionLabel(node, ancestors) {
81
86
  function isPascalCaseComponent(name) {
82
87
  return /^[A-Z][a-zA-Z0-9]*$/.test(name);
83
88
  }
89
+ function isEventHandlerName(name) {
90
+ return /^(?:on|handle)[A-Z]/.test(name);
91
+ }
84
92
  function findEnclosingScopeNode(ancestors, selfNode) {
85
93
  for (let i = ancestors.length - 1; i >= 0; i--) {
86
94
  const anc = ancestors[i];
@@ -90,12 +98,80 @@ function findEnclosingScopeNode(ancestors, selfNode) {
90
98
  }
91
99
  return ancestors[0];
92
100
  }
101
+ function findEnclosingFunction(ancestors, selfNode) {
102
+ for (let i = ancestors.length - 1; i >= 0; i--) {
103
+ if (ancestors[i] !== selfNode && FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
104
+ return ancestors[i];
105
+ }
106
+ }
107
+ return null;
108
+ }
109
+ function findOutermostModuleFunction(ancestors) {
110
+ const fnList = [];
111
+ for (let i = 0; i < ancestors.length; i++) {
112
+ if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
113
+ fnList.push(ancestors[i]);
114
+ }
115
+ }
116
+ if (fnList.length === 0) return null;
117
+ if (fnList.length === 1) return fnList[0];
118
+ return fnList[1];
119
+ }
120
+ function isZeroArgIifeFactoryFunction(node) {
121
+ if (!node || node.params && node.params.length > 0) return false;
122
+ if (!node.body || node.body.type !== "BlockStatement") return false;
123
+ const stmts = (node.body.body || []).filter(
124
+ (s) => !(s.type === "ExpressionStatement" && s.directive)
125
+ );
126
+ if (stmts.length !== 1 || stmts[0].type !== "ReturnStatement") return false;
127
+ const retArg = stmts[0].argument;
128
+ if (!retArg || retArg.type !== "CallExpression") return false;
129
+ const callee = retArg.callee;
130
+ return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
131
+ }
132
+ function containsLoopOrAnimation(fnNode) {
133
+ let found = false;
134
+ walk.simple(fnNode, {
135
+ ForStatement() {
136
+ found = true;
137
+ },
138
+ ForInStatement() {
139
+ found = true;
140
+ },
141
+ ForOfStatement() {
142
+ found = true;
143
+ },
144
+ WhileStatement() {
145
+ found = true;
146
+ },
147
+ DoWhileStatement() {
148
+ found = true;
149
+ },
150
+ CallExpression(callNode) {
151
+ let cName = "";
152
+ let mProp = "";
153
+ if (callNode.callee?.type === "Identifier") {
154
+ cName = callNode.callee.name;
155
+ } else if (callNode.callee?.type === "MemberExpression" && !callNode.callee.computed && callNode.callee.property?.type === "Identifier") {
156
+ mProp = callNode.callee.property.name;
157
+ }
158
+ if (ANIMATION_FRAME_CALLS.has(cName) || ANIMATION_FRAME_CALLS.has(mProp)) {
159
+ found = true;
160
+ }
161
+ }
162
+ });
163
+ return found;
164
+ }
93
165
  function analyzeAstHotPaths(ast) {
94
166
  const hotFunctionNodes = /* @__PURE__ */ new WeakSet();
95
167
  const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
96
168
  const hotExemptNodes = /* @__PURE__ */ new WeakSet();
169
+ const serializedFunctionNodes = /* @__PURE__ */ new WeakSet();
170
+ const serializedWorkerNodes = /* @__PURE__ */ new Set();
171
+ const trueHotNodes = /* @__PURE__ */ new Set();
172
+ const shallowComponentNodes = /* @__PURE__ */ new Set();
173
+ const coldForcedNodes = /* @__PURE__ */ new Set();
97
174
  const directHotNodes = /* @__PURE__ */ new Set();
98
- const serializedFunctionNodes = /* @__PURE__ */ new Set();
99
175
  const serializerHelperNodes = /* @__PURE__ */ new Set();
100
176
  const allFunctions = [];
101
177
  const fnByName = /* @__PURE__ */ new Map();
@@ -140,42 +216,12 @@ function analyzeAstHotPaths(ast) {
140
216
  return cur;
141
217
  }
142
218
  function markSerializedFunction(node) {
219
+ serializedWorkerNodes.add(node);
143
220
  serializedFunctionNodes.add(node);
144
221
  hotFunctionNodes.add(node);
145
222
  directHotNodes.add(node);
146
223
  hotExemptNodes.add(node);
147
224
  }
148
- function findEnclosingFunction(ancestors, selfNode) {
149
- for (let i = ancestors.length - 1; i >= 0; i--) {
150
- if (ancestors[i] !== selfNode && FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
151
- return ancestors[i];
152
- }
153
- }
154
- return null;
155
- }
156
- function findOutermostModuleFunction(ancestors) {
157
- const fnList = [];
158
- for (let i = 0; i < ancestors.length; i++) {
159
- if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
160
- fnList.push(ancestors[i]);
161
- }
162
- }
163
- if (fnList.length === 0) return null;
164
- if (fnList.length === 1) return fnList[0];
165
- return fnList[1];
166
- }
167
- function isZeroArgIifeFactoryFunction(node) {
168
- if (!node || node.params && node.params.length > 0) return false;
169
- if (!node.body || node.body.type !== "BlockStatement") return false;
170
- const stmts = (node.body.body || []).filter(
171
- (s) => !(s.type === "ExpressionStatement" && s.directive)
172
- );
173
- if (stmts.length !== 1 || stmts[0].type !== "ReturnStatement") return false;
174
- const retArg = stmts[0].argument;
175
- if (!retArg || retArg.type !== "CallExpression") return false;
176
- const callee = retArg.callee;
177
- return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
178
- }
179
225
  function registerFunctionNode(node, ancestors) {
180
226
  const name = getFunctionLabel(node, ancestors);
181
227
  allFunctions.push({ node, name });
@@ -228,6 +274,7 @@ function analyzeAstHotPaths(ast) {
228
274
  }
229
275
  fnScopeChain.set(node, chain);
230
276
  if (isPascalCaseComponent(name)) {
277
+ shallowComponentNodes.add(node);
231
278
  hotFunctionNodes.add(node);
232
279
  directHotNodes.add(node);
233
280
  }
@@ -397,9 +444,15 @@ function analyzeAstHotPaths(ast) {
397
444
  const outerFn = findOutermostModuleFunction(ancestors);
398
445
  if (outerFn) markSerializedFunction(outerFn);
399
446
  }
400
- if (ARRAY_HOF_METHODS.has(memberProp) || calleeName === "requestAnimationFrame" || memberProp === "requestAnimationFrame" || calleeName === "cancelAnimationFrame" || memberProp === "cancelAnimationFrame") {
447
+ if (ANIMATION_FRAME_CALLS.has(calleeName) || ANIMATION_FRAME_CALLS.has(memberProp)) {
448
+ if (enclosingFn) {
449
+ trueHotNodes.add(enclosingFn);
450
+ hotFunctionNodes.add(enclosingFn);
451
+ directHotNodes.add(enclosingFn);
452
+ }
401
453
  for (const arg of node.arguments || []) {
402
454
  if (FUNCTION_NODE_TYPES.has(arg.type)) {
455
+ trueHotNodes.add(arg);
403
456
  hotFunctionNodes.add(arg);
404
457
  directHotNodes.add(arg);
405
458
  hotExemptNodes.add(arg);
@@ -412,8 +465,48 @@ function analyzeAstHotPaths(ast) {
412
465
  }
413
466
  }
414
467
  }
415
- if (UI_HOOK_OR_RENDER_CALLS.has(calleeName) || UI_HOOK_OR_RENDER_CALLS.has(memberProp)) {
468
+ if (ARRAY_HOF_METHODS.has(memberProp)) {
469
+ if (enclosingFn !== null) {
470
+ for (const arg of node.arguments || []) {
471
+ if (FUNCTION_NODE_TYPES.has(arg.type)) {
472
+ trueHotNodes.add(arg);
473
+ hotFunctionNodes.add(arg);
474
+ directHotNodes.add(arg);
475
+ hotExemptNodes.add(arg);
476
+ } else if (arg?.type === "Identifier") {
477
+ allCallSites.push({
478
+ scopeNode: currentScope,
479
+ calleeKey: arg.name,
480
+ args: [arg]
481
+ });
482
+ }
483
+ }
484
+ } else {
485
+ for (const arg of node.arguments || []) {
486
+ if (FUNCTION_NODE_TYPES.has(arg.type)) {
487
+ coldForcedNodes.add(arg);
488
+ }
489
+ }
490
+ }
491
+ }
492
+ if (calleeName === "useEffect" || memberProp === "useEffect" || calleeName === "useLayoutEffect" || memberProp === "useLayoutEffect") {
493
+ const effectArg = node.arguments?.[0];
494
+ if (effectArg && FUNCTION_NODE_TYPES.has(effectArg.type)) {
495
+ if (!containsLoopOrAnimation(effectArg)) {
496
+ coldForcedNodes.add(effectArg);
497
+ if (effectArg.body?.type === "BlockStatement") {
498
+ for (const s of effectArg.body.body || []) {
499
+ if (s.type === "ReturnStatement" && s.argument && FUNCTION_NODE_TYPES.has(s.argument.type) && !containsLoopOrAnimation(s.argument)) {
500
+ coldForcedNodes.add(s.argument);
501
+ }
502
+ }
503
+ }
504
+ }
505
+ }
506
+ }
507
+ if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp)) {
416
508
  if (enclosingFn) {
509
+ shallowComponentNodes.add(enclosingFn);
417
510
  hotFunctionNodes.add(enclosingFn);
418
511
  directHotNodes.add(enclosingFn);
419
512
  }
@@ -421,23 +514,48 @@ function analyzeAstHotPaths(ast) {
421
514
  },
422
515
  ForStatement(node, _state, ancestors) {
423
516
  hotExemptNodes.add(node);
424
- markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
517
+ const enc = findEnclosingFunction(ancestors);
518
+ if (enc) {
519
+ trueHotNodes.add(enc);
520
+ hotFunctionNodes.add(enc);
521
+ directHotNodes.add(enc);
522
+ }
425
523
  },
426
524
  ForInStatement(node, _state, ancestors) {
427
525
  hotExemptNodes.add(node);
428
- markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
526
+ const enc = findEnclosingFunction(ancestors);
527
+ if (enc) {
528
+ trueHotNodes.add(enc);
529
+ hotFunctionNodes.add(enc);
530
+ directHotNodes.add(enc);
531
+ }
429
532
  },
430
533
  ForOfStatement(node, _state, ancestors) {
431
534
  hotExemptNodes.add(node);
432
- markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
535
+ const enc = findEnclosingFunction(ancestors);
536
+ if (enc) {
537
+ trueHotNodes.add(enc);
538
+ hotFunctionNodes.add(enc);
539
+ directHotNodes.add(enc);
540
+ }
433
541
  },
434
542
  WhileStatement(node, _state, ancestors) {
435
543
  hotExemptNodes.add(node);
436
- markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
544
+ const enc = findEnclosingFunction(ancestors);
545
+ if (enc) {
546
+ trueHotNodes.add(enc);
547
+ hotFunctionNodes.add(enc);
548
+ directHotNodes.add(enc);
549
+ }
437
550
  },
438
551
  DoWhileStatement(node, _state, ancestors) {
439
552
  hotExemptNodes.add(node);
440
- markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
553
+ const enc = findEnclosingFunction(ancestors);
554
+ if (enc) {
555
+ trueHotNodes.add(enc);
556
+ hotFunctionNodes.add(enc);
557
+ directHotNodes.add(enc);
558
+ }
441
559
  }
442
560
  });
443
561
  for (const callSite of allCallSites) {
@@ -454,59 +572,113 @@ function analyzeAstHotPaths(ast) {
454
572
  markSerializedFunction(targetNode);
455
573
  }
456
574
  }
457
- const forwardHotSet = new Set(directHotNodes);
575
+ for (const fn of allFunctions) {
576
+ if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node)) {
577
+ if (fn.node.async === true || isEventHandlerName(fn.name)) {
578
+ coldForcedNodes.add(fn.node);
579
+ }
580
+ }
581
+ }
458
582
  let forwardChanged = true;
459
583
  while (forwardChanged) {
460
584
  forwardChanged = false;
461
585
  for (const fn of allFunctions) {
462
- if (forwardHotSet.has(fn.node)) continue;
586
+ if (coldForcedNodes.has(fn.node)) continue;
463
587
  const chain = fnScopeChain.get(fn.node);
464
588
  if (!chain) continue;
465
589
  for (const anc of chain) {
466
- if (anc !== fn.node && (serializedFunctionNodes.has(anc) || forwardHotSet.has(anc))) {
467
- forwardHotSet.add(fn.node);
468
- hotFunctionNodes.add(fn.node);
469
- hotExemptNodes.add(fn.node);
470
- if (serializedFunctionNodes.has(anc)) {
590
+ if (anc === fn.node) continue;
591
+ if (serializedWorkerNodes.has(anc)) {
592
+ if (!serializedWorkerNodes.has(fn.node)) {
593
+ serializedWorkerNodes.add(fn.node);
471
594
  serializedFunctionNodes.add(fn.node);
595
+ hotFunctionNodes.add(fn.node);
596
+ hotExemptNodes.add(fn.node);
597
+ forwardChanged = true;
598
+ }
599
+ break;
600
+ }
601
+ const isModuleContainer = (fnScopeChain.get(anc)?.length ?? 0) <= 1;
602
+ if (trueHotNodes.has(anc) && !shallowComponentNodes.has(anc) && !isModuleContainer) {
603
+ if (!trueHotNodes.has(fn.node)) {
604
+ trueHotNodes.add(fn.node);
605
+ hotFunctionNodes.add(fn.node);
606
+ hotExemptNodes.add(fn.node);
607
+ forwardChanged = true;
472
608
  }
473
- forwardChanged = true;
474
609
  break;
475
610
  }
476
611
  }
477
612
  }
478
- for (const callerNode of Array.from(forwardHotSet)) {
613
+ for (const callerNode of Array.from(serializedWorkerNodes)) {
479
614
  const calleeNames = callerToCallees.get(callerNode);
480
615
  if (!calleeNames) continue;
481
616
  for (const cName of calleeNames) {
482
617
  const targetNode = resolveCalleeNode(callerNode, cName);
483
- if (targetNode && !forwardHotSet.has(targetNode)) {
484
- forwardHotSet.add(targetNode);
618
+ if (targetNode && !serializedWorkerNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
619
+ serializedWorkerNodes.add(targetNode);
620
+ serializedFunctionNodes.add(targetNode);
621
+ hotFunctionNodes.add(targetNode);
622
+ hotExemptNodes.add(targetNode);
623
+ forwardChanged = true;
624
+ }
625
+ }
626
+ }
627
+ for (const callerNode of Array.from(trueHotNodes)) {
628
+ const calleeNames = callerToCallees.get(callerNode);
629
+ if (!calleeNames) continue;
630
+ for (const cName of calleeNames) {
631
+ const targetNode = resolveCalleeNode(callerNode, cName);
632
+ if (targetNode && !trueHotNodes.has(targetNode) && !coldForcedNodes.has(targetNode)) {
633
+ trueHotNodes.add(targetNode);
485
634
  hotFunctionNodes.add(targetNode);
486
635
  hotExemptNodes.add(targetNode);
487
- if (serializedFunctionNodes.has(callerNode)) {
488
- serializedFunctionNodes.add(targetNode);
489
- }
490
636
  forwardChanged = true;
491
637
  }
492
638
  }
493
639
  }
494
640
  }
641
+ const calleeToCallers = /* @__PURE__ */ new Map();
642
+ for (const [callerNode, calleeNames] of callerToCallees.entries()) {
643
+ for (const cName of calleeNames) {
644
+ const targetNode = resolveCalleeNode(callerNode, cName);
645
+ if (targetNode) {
646
+ let set = calleeToCallers.get(targetNode);
647
+ if (!set) {
648
+ set = /* @__PURE__ */ new Set();
649
+ calleeToCallers.set(targetNode, set);
650
+ }
651
+ set.add(callerNode);
652
+ }
653
+ }
654
+ }
495
655
  let changed = true;
496
656
  while (changed) {
497
657
  changed = false;
498
658
  for (const [callerNode, calleeNames] of callerToCallees.entries()) {
499
- if (hotFunctionNodes.has(callerNode)) continue;
659
+ if (hotFunctionNodes.has(callerNode) || shallowComponentNodes.has(callerNode) || coldForcedNodes.has(callerNode)) {
660
+ continue;
661
+ }
500
662
  for (const cName of calleeNames) {
501
663
  const targetNode = resolveCalleeNode(callerNode, cName);
502
- if (targetNode && hotFunctionNodes.has(targetNode)) {
503
- hotFunctionNodes.add(callerNode);
504
- changed = true;
505
- break;
664
+ if (targetNode && trueHotNodes.has(targetNode)) {
665
+ const callers = calleeToCallers.get(targetNode);
666
+ const isDedicatedPipeline = callers && callers.size <= 2;
667
+ if (isDedicatedPipeline) {
668
+ trueHotNodes.add(callerNode);
669
+ hotFunctionNodes.add(callerNode);
670
+ hotExemptNodes.add(callerNode);
671
+ changed = true;
672
+ break;
673
+ }
506
674
  }
507
675
  }
508
676
  }
509
677
  }
678
+ for (const node of coldForcedNodes) {
679
+ hotFunctionNodes.delete(node);
680
+ hotExemptNodes.delete(node);
681
+ }
510
682
  const hotFunctionsSkipped = [];
511
683
  const coldFunctionsProtected = [];
512
684
  for (const fn of allFunctions) {
@@ -525,56 +697,454 @@ function analyzeAstHotPaths(ast) {
525
697
  },
526
698
  hotFunctionNodes,
527
699
  coldFunctionNodes,
528
- hotExemptNodes
700
+ hotExemptNodes,
701
+ serializedFunctionNodes
529
702
  };
530
703
  }
531
- function markEnclosingFunctionHot(ancestors, hotSet, directHotSet) {
532
- for (let i = ancestors.length - 1; i >= 0; i--) {
533
- if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
534
- hotSet.add(ancestors[i]);
535
- if (directHotSet) {
536
- directHotSet.add(ancestors[i]);
704
+
705
+ // src/ast/string-vault.ts
706
+ import * as acorn2 from "acorn";
707
+ import * as walk2 from "acorn-walk";
708
+
709
+ // src/ast/codegen.ts
710
+ import { generate, baseGenerator } from "astring";
711
+ function derivePolymorphicIdent(seed, role) {
712
+ let h = (2166136261 ^ seed >>> 0) >>> 0;
713
+ for (let i = 0; i < role.length; i++) {
714
+ h ^= role.charCodeAt(i);
715
+ h = Math.imul(h, 16777619) >>> 0;
716
+ }
717
+ const rolePrefixes = {
718
+ vault: "_a",
719
+ shield: "$b",
720
+ decoy: "_d",
721
+ shader: "_s",
722
+ vm: "_m",
723
+ wasm: "_w",
724
+ salted: "_k",
725
+ windowKey: "_z"
726
+ };
727
+ const prefix = rolePrefixes[role] ?? `_${String.fromCharCode(97 + h % 26)}`;
728
+ const suffix = ((h >>> 4) % 1296).toString(36).padStart(2, "0");
729
+ return `${prefix}${suffix}`;
730
+ }
731
+ var OPERATOR_PRECEDENCE = {
732
+ "||": 2,
733
+ "??": 3,
734
+ "&&": 4,
735
+ "|": 5,
736
+ "^": 6,
737
+ "&": 7,
738
+ "==": 8,
739
+ "!=": 8,
740
+ "===": 8,
741
+ "!==": 8,
742
+ "<": 9,
743
+ ">": 9,
744
+ "<=": 9,
745
+ ">=": 9,
746
+ "in": 9,
747
+ "instanceof": 9,
748
+ "<<": 10,
749
+ ">>": 10,
750
+ ">>>": 10,
751
+ "+": 11,
752
+ "-": 11,
753
+ "*": 12,
754
+ "%": 12,
755
+ "/": 12,
756
+ "**": 13
757
+ };
758
+ var NEEDS_PARENTHESES = 17;
759
+ function expressionNeedsParenthesis(state, node, parentNode, isRightHand) {
760
+ const nodePrecedence = state.expressionsPrecedence[node.type];
761
+ if (nodePrecedence === NEEDS_PARENTHESES) {
762
+ return true;
763
+ }
764
+ const parentNodePrecedence = state.expressionsPrecedence[parentNode.type];
765
+ if (nodePrecedence !== parentNodePrecedence) {
766
+ return !isRightHand && nodePrecedence === 15 && parentNodePrecedence === 14 && parentNode.operator === "**" || nodePrecedence < parentNodePrecedence;
767
+ }
768
+ if (nodePrecedence !== 13 && nodePrecedence !== 14) {
769
+ return false;
770
+ }
771
+ if (node.operator === "**" && parentNode.operator === "**") {
772
+ return !isRightHand;
773
+ }
774
+ if (nodePrecedence === 13 && parentNodePrecedence === 13 && (node.operator === "??" || parentNode.operator === "??")) {
775
+ return true;
776
+ }
777
+ if (isRightHand) {
778
+ return OPERATOR_PRECEDENCE[node.operator] <= OPERATOR_PRECEDENCE[parentNode.operator];
779
+ }
780
+ return OPERATOR_PRECEDENCE[node.operator] < OPERATOR_PRECEDENCE[parentNode.operator];
781
+ }
782
+ function formatExpression(state, node, parentNode, isRightHand) {
783
+ const generator = state.generator;
784
+ if (expressionNeedsParenthesis(state, node, parentNode, isRightHand)) {
785
+ state.write("(");
786
+ generator[node.type](node, state);
787
+ state.write(")");
788
+ } else {
789
+ generator[node.type](node, state);
790
+ }
791
+ }
792
+ function formatSequence(state, expressions) {
793
+ const length = expressions.length;
794
+ if (length > 0) {
795
+ state.write("(");
796
+ state.generator[expressions[0].type](expressions[0], state);
797
+ for (let i = 1; i < length; i++) {
798
+ state.write(",");
799
+ state.generator[expressions[i].type](expressions[i], state);
800
+ }
801
+ state.write(")");
802
+ } else {
803
+ state.write("()");
804
+ }
805
+ }
806
+ function expressionStartsWith(node, char) {
807
+ if (!node) return false;
808
+ if (node.type === "UnaryExpression" && node.prefix) {
809
+ return node.operator === char;
810
+ }
811
+ if (node.type === "UpdateExpression" && node.prefix) {
812
+ return node.operator[0] === char;
813
+ }
814
+ return false;
815
+ }
816
+ function expressionEndsWith(node, char) {
817
+ if (!node) return false;
818
+ if (node.type === "UpdateExpression" && !node.prefix) {
819
+ return node.operator[0] === char;
820
+ }
821
+ return false;
822
+ }
823
+ function isRegExp(node) {
824
+ return node && (node.type === "Literal" && !!node.regex || node.type === "RegExpLiteral");
825
+ }
826
+ var compactGenerator = Object.assign({}, baseGenerator, {
827
+ BinaryExpression(node, state) {
828
+ const isIn = node.operator === "in";
829
+ if (isIn) {
830
+ state.write("(");
831
+ }
832
+ formatExpression(state, node.left, node, false);
833
+ const op = node.operator;
834
+ let spaceBefore = false;
835
+ let spaceAfter = false;
836
+ if (op === "in" || op === "instanceof") {
837
+ spaceBefore = true;
838
+ spaceAfter = true;
839
+ } else {
840
+ if ((op === "+" || op === "-") && expressionEndsWith(node.left, op) && !expressionNeedsParenthesis(state, node.left, node, false)) {
841
+ spaceBefore = true;
537
842
  }
538
- break;
843
+ if ((op === "+" || op === "-") && expressionStartsWith(node.right, op) && !expressionNeedsParenthesis(state, node.right, node, true) || op === "/" && isRegExp(node.right)) {
844
+ spaceAfter = true;
845
+ }
846
+ }
847
+ if (spaceBefore) state.write(" ");
848
+ state.write(op);
849
+ if (spaceAfter) state.write(" ");
850
+ formatExpression(state, node.right, node, true);
851
+ if (isIn) {
852
+ state.write(")");
853
+ }
854
+ },
855
+ LogicalExpression(node, state) {
856
+ formatExpression(state, node.left, node, false);
857
+ state.write(node.operator);
858
+ formatExpression(state, node.right, node, true);
859
+ },
860
+ AssignmentExpression(node, state) {
861
+ this[node.left.type](node.left, state);
862
+ const op = node.operator;
863
+ if (op.endsWith("+") && expressionStartsWith(node.right, "+") || op.endsWith("-") && expressionStartsWith(node.right, "-") || op.endsWith("/") && isRegExp(node.right)) {
864
+ state.write(op + " ");
865
+ } else {
866
+ state.write(op);
867
+ }
868
+ this[node.right.type](node.right, state);
869
+ },
870
+ ConditionalExpression(node, state) {
871
+ const test = node.test;
872
+ const precedence = state.expressionsPrecedence[test.type];
873
+ if (precedence === NEEDS_PARENTHESES || precedence <= state.expressionsPrecedence.ConditionalExpression) {
874
+ state.write("(");
875
+ this[test.type](test, state);
876
+ state.write(")");
877
+ } else {
878
+ this[test.type](test, state);
879
+ }
880
+ state.write("?");
881
+ this[node.consequent.type](node.consequent, state);
882
+ state.write(":");
883
+ this[node.alternate.type](node.alternate, state);
884
+ },
885
+ ArrayExpression(node, state) {
886
+ state.write("[");
887
+ const elements = node.elements;
888
+ const length = elements.length;
889
+ for (let i = 0; i < length; i++) {
890
+ const element = elements[i];
891
+ if (element != null) {
892
+ this[element.type](element, state);
893
+ }
894
+ if (i + 1 < length) {
895
+ state.write(",");
896
+ }
897
+ }
898
+ state.write("]");
899
+ },
900
+ ObjectExpression(node, state) {
901
+ state.write("{");
902
+ const properties = node.properties;
903
+ const length = properties.length;
904
+ for (let i = 0; i < length; i++) {
905
+ const property = properties[i];
906
+ this[property.type](property, state);
907
+ if (i + 1 < length) {
908
+ state.write(",");
909
+ }
910
+ }
911
+ state.write("}");
912
+ },
913
+ Property(node, state) {
914
+ if (node.method || node.kind[0] !== "i") {
915
+ this.MethodDefinition(node, state);
916
+ } else {
917
+ if (!node.shorthand) {
918
+ if (node.computed) {
919
+ state.write("[");
920
+ this[node.key.type](node.key, state);
921
+ state.write("]");
922
+ } else {
923
+ this[node.key.type](node.key, state);
924
+ }
925
+ state.write(":");
926
+ }
927
+ this[node.value.type](node.value, state);
928
+ }
929
+ },
930
+ CallExpression(node, state) {
931
+ formatExpression(state, node.callee, node, false);
932
+ if (node.optional) {
933
+ state.write("?.");
934
+ }
935
+ formatSequence(state, node.arguments);
936
+ },
937
+ SequenceExpression(node, state) {
938
+ formatSequence(state, node.expressions);
939
+ },
940
+ FunctionDeclaration(node, state) {
941
+ state.write(
942
+ (node.async ? "async " : "") + (node.generator ? "function* " : "function ") + (node.id ? node.id.name : ""),
943
+ node
944
+ );
945
+ formatSequence(state, node.params);
946
+ this[node.body.type](node.body, state);
947
+ },
948
+ FunctionExpression(node, state) {
949
+ compactGenerator.FunctionDeclaration.call(this, node, state);
950
+ },
951
+ ArrowFunctionExpression(node, state) {
952
+ state.write(node.async ? "async " : "", node);
953
+ const params = node.params;
954
+ if (params != null) {
955
+ if (params.length === 0) {
956
+ state.write("()");
957
+ } else if (params.length === 1 && params[0].type === "Identifier") {
958
+ state.write(params[0].name, params[0]);
959
+ } else {
960
+ formatSequence(state, node.params);
961
+ }
962
+ } else {
963
+ state.write("()");
964
+ }
965
+ state.write("=>");
966
+ if (node.body.type[0] === "O") {
967
+ state.write("(");
968
+ this.ObjectExpression(node.body, state);
969
+ state.write(")");
970
+ } else {
971
+ this[node.body.type](node.body, state);
972
+ }
973
+ },
974
+ ForStatement(node, state) {
975
+ state.write("for(");
976
+ if (node.init != null) {
977
+ const init = node.init;
978
+ if (init.type[0] === "V") {
979
+ this.VariableDeclaration(init, state);
980
+ } else {
981
+ this[init.type](init, state);
982
+ state.write(";");
983
+ }
984
+ } else {
985
+ state.write(";");
986
+ }
987
+ if (node.test) {
988
+ this[node.test.type](node.test, state);
989
+ }
990
+ state.write(";");
991
+ if (node.update) {
992
+ this[node.update.type](node.update, state);
993
+ }
994
+ state.write(")");
995
+ this[node.body.type](node.body, state);
996
+ },
997
+ IfStatement(node, state) {
998
+ state.write("if(");
999
+ this[node.test.type](node.test, state);
1000
+ state.write(")");
1001
+ this[node.consequent.type](node.consequent, state);
1002
+ if (node.alternate != null) {
1003
+ if (node.consequent.type === "BlockStatement") {
1004
+ state.write("else");
1005
+ } else {
1006
+ state.write(" else");
1007
+ }
1008
+ if (node.alternate.type === "BlockStatement") {
1009
+ this[node.alternate.type](node.alternate, state);
1010
+ } else if (node.alternate.type === "IfStatement") {
1011
+ state.write(" ");
1012
+ this[node.alternate.type](node.alternate, state);
1013
+ } else {
1014
+ state.write(" ");
1015
+ this[node.alternate.type](node.alternate, state);
1016
+ }
1017
+ }
1018
+ },
1019
+ VariableDeclaration(node, state) {
1020
+ state.write(node.kind + " ");
1021
+ const declarations = node.declarations;
1022
+ const length = declarations.length;
1023
+ for (let i = 0; i < length; i++) {
1024
+ this.VariableDeclarator(declarations[i], state);
1025
+ if (i + 1 < length) {
1026
+ state.write(",");
1027
+ }
1028
+ }
1029
+ state.write(";");
1030
+ },
1031
+ VariableDeclarator(node, state) {
1032
+ this[node.id.type](node.id, state);
1033
+ if (node.init != null) {
1034
+ state.write("=");
1035
+ this[node.init.type](node.init, state);
539
1036
  }
1037
+ },
1038
+ ReturnStatement(node, state) {
1039
+ state.write("return");
1040
+ if (node.argument) {
1041
+ state.write(" ");
1042
+ this[node.argument.type](node.argument, state);
1043
+ }
1044
+ state.write(";");
1045
+ }
1046
+ });
1047
+ function generateCompactJs(ast) {
1048
+ return generate(ast, {
1049
+ generator: compactGenerator,
1050
+ indent: "",
1051
+ lineEnd: ""
1052
+ });
1053
+ }
1054
+
1055
+ // src/runtime/integrity-guard.ts
1056
+ var FNV_OFFSET_BASIS = 2166136261;
1057
+ var FNV_PRIME = 16777619;
1058
+ function computeIntegrityHash(source, seed = 0) {
1059
+ let hash = (FNV_OFFSET_BASIS ^ seed >>> 0) >>> 0;
1060
+ for (let i = 0; i < source.length; i++) {
1061
+ hash ^= source.charCodeAt(i);
1062
+ hash = Math.imul(hash, FNV_PRIME) >>> 0;
540
1063
  }
1064
+ return hash >>> 0;
1065
+ }
1066
+
1067
+ // src/runtime/devtools-deterrent.ts
1068
+ function deriveIntegrityFnName(seed) {
1069
+ return derivePolymorphicIdent(seed, "shield");
1070
+ }
1071
+ function deriveWindowKeySymbol(seed) {
1072
+ return derivePolymorphicIdent(seed, "windowKey");
1073
+ }
1074
+ function createDeterrentSnippet(config) {
1075
+ const seed = config.seed >>> 0;
1076
+ const deterrentMode = config.deterrentMode ?? "passive";
1077
+ const fnName = deriveIntegrityFnName(seed);
1078
+ const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
1079
+ const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=function(){return 0;};" : "";
1080
+ return `(function ${fnName}(w){if(w){try{var s=Function.prototype.toString,n=w.navigator||0,src=s.call(${fnName}),t=s.call(s).indexOf('[native code]')<0||/\\n/.test(src)||n.webdriver||/HeadlessChrome/.test(n.userAgent);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=(h&31);if(t){w.__unpeek_tampered=!0;w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0;String.prototype._u=14;w['${sym}']=d^29;try{${consoleSilence}w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{w['${sym}']=d;}}catch(e){}}})(typeof window!=='undefined'&&window);`;
1081
+ }
1082
+
1083
+ // src/runtime/index.ts
1084
+ function generateRuntimeShield(config) {
1085
+ const seed = config.seed >>> 0;
1086
+ const windowKeySymbol = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
1087
+ const integrityCheckFnName = deriveIntegrityFnName(seed);
1088
+ const preambleCode = createDeterrentSnippet({
1089
+ ...config,
1090
+ windowKeySymbol
1091
+ });
1092
+ const fnStart = preambleCode.indexOf("function");
1093
+ const fnEnd = preambleCode.lastIndexOf("(") - 1;
1094
+ const fnDecl = preambleCode.slice(fnStart, fnEnd);
1095
+ const computedHash = computeIntegrityHash(fnDecl, 0);
1096
+ const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computedHash;
1097
+ const expectedDelta = config.expectedDelta !== void 0 ? config.expectedDelta & 31 : computedHash >>> 0 & 31;
1098
+ return {
1099
+ preambleCode,
1100
+ integrityCheckFnName,
1101
+ expectedHash,
1102
+ windowKeySymbol,
1103
+ expectedDelta
1104
+ };
541
1105
  }
542
1106
 
543
1107
  // src/ast/string-vault.ts
544
- import * as acorn2 from "acorn";
545
- import * as walk2 from "acorn-walk";
1108
+ var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
546
1109
  var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
547
1110
  "use strict",
548
1111
  "use client",
549
1112
  "use server",
550
1113
  "use asm"
551
1114
  ]);
552
- var HELPER_TEMPLATE = acorn2.parse(
553
- `var _ = (function f(a){return a.map(function(s){var o="";for(var j=0;j<s.length;j++)o+=String.fromCharCode(s.charCodeAt(j)^(((0^((a._u||/\\n/.test(f)*14)|((j&1)*0)))&30)|1));return o;});})([]);`,
554
- { ecmaVersion: "latest", sourceType: "script" }
555
- ).body[0];
556
- function createVaultHelperAst(cacheVarName, encryptedPayloads, mask, step) {
557
- const node = structuredClone(HELPER_TEMPLATE);
558
- node.declarations[0].id.name = cacheVarName;
559
- node.declarations[0].init.arguments[0].elements = encryptedPayloads.map(
560
- (str) => ({
561
- type: "Literal",
562
- value: str,
563
- raw: JSON.stringify(str)
564
- })
565
- );
566
- const outerFn = node.declarations[0].init.callee;
567
- const returnStmt = outerFn.body.body[0];
568
- const innerFn = returnStmt.argument.arguments[0];
569
- const forStmt = innerFn.body.body[1];
570
- const expr = forStmt.body.type === "BlockStatement" ? forStmt.body.body[0].expression : forStmt.body.expression;
571
- const binaryXor = expr.right.arguments[0];
572
- const innerLeft = binaryXor.right.left.left;
573
- innerLeft.left.value = mask;
574
- innerLeft.left.raw = String(mask);
575
- innerLeft.right.right.right.value = step;
576
- innerLeft.right.right.right.raw = String(step);
577
- return node;
1115
+ var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
1116
+ "id",
1117
+ "type",
1118
+ "key",
1119
+ "ref",
1120
+ "className",
1121
+ "style",
1122
+ "name",
1123
+ "value",
1124
+ "children",
1125
+ "src",
1126
+ "href",
1127
+ "alt",
1128
+ "role",
1129
+ "tabIndex"
1130
+ ]);
1131
+ var TAILWIND_TOKEN_RE = /^(?:flex|grid|block|inline|hidden|relative|absolute|fixed|w-|h-|min-|max-|p[xytrbl]?-|m[xytrbl]?-|space-[xy]-|text-|font-|bg-|border|rounded|shadow|ring|outline|transition|duration|opacity|cursor|pointer-events|select-|items-|justify-|gap-|overflow-|z-|inset-|top-|left-|right-|bottom-|hover:|focus:|focus-visible:|disabled:|dark:|data-\[|aria-|\[&_)/;
1132
+ var SVG_PATH_RE = /^[Mm]\s*-?\d+(?:\.\d+)?[\s,]+-?\d+/;
1133
+ var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
1134
+ function shouldEncryptString(val, minLen) {
1135
+ if (val.length < minLen || DIRECTIVE_STRINGS.has(val)) return false;
1136
+ if (SVG_PATH_RE.test(val)) return false;
1137
+ if (val.includes(" ")) {
1138
+ const tokens = val.trim().split(/\s+/);
1139
+ if (tokens.length >= 3) {
1140
+ let twHits = 0;
1141
+ for (const t of tokens) {
1142
+ if (TAILWIND_TOKEN_RE.test(t)) twHits++;
1143
+ }
1144
+ if (twHits / tokens.length >= 0.5) return false;
1145
+ }
1146
+ }
1147
+ return true;
578
1148
  }
579
1149
  function computeFnv1aHash(input, seed = 2166136261) {
580
1150
  let hash = seed >>> 0;
@@ -584,31 +1154,127 @@ function computeFnv1aHash(input, seed = 2166136261) {
584
1154
  }
585
1155
  return hash >>> 0;
586
1156
  }
587
- function encodeStringWithSeed(str, mask, step) {
1157
+ function createPermutationTable(seed) {
1158
+ let s = (seed || 305419896) >>> 0;
1159
+ function xorshift() {
1160
+ s ^= s << 13;
1161
+ s ^= s >>> 17;
1162
+ s ^= s << 5;
1163
+ return s >>> 0;
1164
+ }
1165
+ const indices = [];
1166
+ for (let i = 0; i < 92; i++) indices.push(i);
1167
+ for (let i = 91; i > 0; i--) {
1168
+ const j = xorshift() % (i + 1);
1169
+ const tmp = indices[i];
1170
+ indices[i] = indices[j];
1171
+ indices[j] = tmp;
1172
+ }
1173
+ const B = new Array(92);
1174
+ for (let i = 0; i < 46; i++) {
1175
+ const a = indices[2 * i];
1176
+ const b = indices[2 * i + 1];
1177
+ B[a] = b;
1178
+ B[b] = a;
1179
+ }
1180
+ let P_CHARS = "";
1181
+ for (let i = 0; i < 92; i++) {
1182
+ P_CHARS += SAFE_ALPHA[B[i]];
1183
+ }
1184
+ return P_CHARS;
1185
+ }
1186
+ function encodeStringWithSeed(str, P_CHARS, expectedRot) {
588
1187
  let out = "";
589
1188
  for (let i = 0; i < str.length; i++) {
590
- const code = str.charCodeAt(i);
591
- const k = (mask ^ (i & 1) * step) & 30 | 1;
592
- out += String.fromCharCode(code ^ k);
1189
+ const c = str.charAt(i);
1190
+ const k = SAFE_ALPHA.indexOf(c);
1191
+ if (k < 0) {
1192
+ out += c;
1193
+ } else {
1194
+ const y = (k + expectedRot) % 92;
1195
+ const z = SAFE_ALPHA.indexOf(P_CHARS.charAt(y));
1196
+ out += SAFE_ALPHA.charAt((z - expectedRot + 92) % 92);
1197
+ }
593
1198
  }
594
1199
  return out;
595
1200
  }
596
- function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
1201
+ function createVaultHelperAst(cacheVarName, encryptedPayloads, fnAst) {
1202
+ return {
1203
+ type: "VariableDeclaration",
1204
+ kind: "var",
1205
+ declarations: [
1206
+ {
1207
+ type: "VariableDeclarator",
1208
+ id: { type: "Identifier", name: cacheVarName },
1209
+ init: {
1210
+ type: "CallExpression",
1211
+ callee: fnAst,
1212
+ arguments: [
1213
+ {
1214
+ type: "ArrayExpression",
1215
+ elements: encryptedPayloads.map((str) => ({
1216
+ type: "Literal",
1217
+ value: str,
1218
+ raw: JSON.stringify(str)
1219
+ }))
1220
+ }
1221
+ ],
1222
+ optional: false
1223
+ }
1224
+ }
1225
+ ]
1226
+ };
1227
+ }
1228
+ function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
1229
+ const b64List = [];
1230
+ const key = seed >>> 0 & 255 ^ 90;
1231
+ for (let idx = 0; idx < shaderPayloads.length; idx++) {
1232
+ const str = shaderPayloads[idx];
1233
+ const buf = Buffer.from(str, "utf8");
1234
+ for (let i = 0; i < buf.length; i++) {
1235
+ buf[i] ^= key;
1236
+ }
1237
+ b64List.push(buf.toString("base64"));
1238
+ }
1239
+ const shaderCode = `var ${shaderVarName} = (function(){var B=${JSON.stringify(
1240
+ b64List
1241
+ )};var k=${key};var b=B.map(function(s){var bin=typeof atob==='function'?atob(s):(typeof Buffer!=='undefined'?Buffer.from(s,'base64').toString('binary'):'');var u=new Uint8Array(bin.length);for(var i=0;i<bin.length;i++)u[i]=bin.charCodeAt(i);return u;});var d=typeof TextDecoder!=='undefined'?new TextDecoder():null;return function(i){var u=b[i];for(var j=0;j<u.length;j++)u[j]^=k;try{return d?d.decode(u):String.fromCharCode.apply(null,u);}finally{for(var j=0;j<u.length;j++)u[j]^=k;}};})();`;
1242
+ return acorn2.parse(shaderCode, { ecmaVersion: "latest", sourceType: "script" }).body[0];
1243
+ }
1244
+ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta) {
1245
+ const cacheVarName = derivePolymorphicIdent(seed, "vault");
1246
+ const shaderVarName = derivePolymorphicIdent(seed, "shader");
1247
+ const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
1248
+ let expDelta = expectedDelta;
1249
+ if (expDelta === void 0) {
1250
+ const shield = generateRuntimeShield({ seed, windowKeySymbol: sym });
1251
+ expDelta = shield.expectedDelta ?? 0;
1252
+ }
597
1253
  const alreadyVaulted = ast.body.some(
598
1254
  (stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
599
- (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uC")
1255
+ (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uC") || d.id.name === cacheVarName || d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f" && d.init.arguments?.[0]?.type === "ArrayExpression")
600
1256
  )
601
1257
  );
602
1258
  if (alreadyVaulted) {
603
1259
  return {
604
1260
  encryptedStringsCount: 0,
605
- integrityToken: computeFnv1aHash("already-vaulted", seed)
1261
+ integrityToken: computeFnv1aHash("already-vaulted", seed),
1262
+ shaderBuffersCount: 0
606
1263
  };
607
1264
  }
608
- const mask = seed >>> 0 & 30 | 3;
609
- const step = 1;
1265
+ const P_CHARS = createPermutationTable(seed);
1266
+ const fBody = `var s=Function.prototype.toString,w=typeof window!=='undefined'&&window,src=s.call(f);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var rot=(h^(a._u||0)^(w&&w['${sym}']!=null?w['${sym}']:${expDelta}))&31;var A="${SAFE_ALPHA}";var P="${P_CHARS}";return a.map(function(s){var o="";for(var j=0;j<s.length;j++){var c=s.charAt(j),k=A.indexOf(c);if(k<0){o+=c;}else{var y=(k+rot)%92;var z=A.indexOf(P.charAt(y));o+=A.charAt((z-rot+92)%92);}}return o;});`;
1267
+ const fnAst = acorn2.parse(`(function f(a){${fBody}})`, {
1268
+ ecmaVersion: "latest",
1269
+ sourceType: "script"
1270
+ }).body[0].expression;
1271
+ const compactFnStr = generateCompactJs(fnAst);
1272
+ const buildH = computeIntegrityHash(compactFnStr, 0);
1273
+ const expectedRot = (buildH ^ 0 ^ expDelta) & 31;
610
1274
  const stringToIndex = /* @__PURE__ */ new Map();
611
1275
  const encryptedPayloads = [];
1276
+ const shaderToIndex = /* @__PURE__ */ new Map();
1277
+ const shaderPayloads = [];
612
1278
  const targetsToReplace = [];
613
1279
  const customWalkBase = {
614
1280
  ...walk2.base,
@@ -623,7 +1289,6 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
623
1289
  Literal(node, _state, ancestors) {
624
1290
  if (typeof node.value !== "string") return;
625
1291
  const val = node.value;
626
- if (val.length < minStringLength) return;
627
1292
  if (DIRECTIVE_STRINGS.has(val)) return;
628
1293
  if (hotExemptNodes) {
629
1294
  for (let i = ancestors.length - 2; i >= 0; i--) {
@@ -641,59 +1306,125 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
641
1306
  if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
642
1307
  return;
643
1308
  }
644
- if (parent.type === "Property" && parent.key === node) {
645
- parent.computed = true;
646
- }
647
1309
  if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
648
1310
  return;
649
1311
  }
650
- let idx = stringToIndex.get(val);
651
- if (idx === void 0) {
652
- idx = encryptedPayloads.length;
653
- stringToIndex.set(val, idx);
654
- encryptedPayloads.push(encodeStringWithSeed(val, mask, step));
1312
+ if (parent.type === "Property" && parent.key === node && !parent.computed) {
1313
+ if (STANDARD_PROP_KEYS.has(val)) {
1314
+ return;
1315
+ }
1316
+ }
1317
+ const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
1318
+ if (isShader) {
1319
+ let idx = shaderToIndex.get(val);
1320
+ if (idx === void 0) {
1321
+ idx = shaderPayloads.length;
1322
+ shaderToIndex.set(val, idx);
1323
+ shaderPayloads.push(val);
1324
+ }
1325
+ targetsToReplace.push({ type: "shader", node, parent, idx });
1326
+ } else {
1327
+ if (!shouldEncryptString(val, minStringLength)) return;
1328
+ let idx = stringToIndex.get(val);
1329
+ if (idx === void 0) {
1330
+ idx = encryptedPayloads.length;
1331
+ stringToIndex.set(val, idx);
1332
+ encryptedPayloads.push(
1333
+ encodeStringWithSeed(val, P_CHARS, expectedRot)
1334
+ );
1335
+ }
1336
+ targetsToReplace.push({ type: "string", node, parent, idx });
1337
+ }
1338
+ },
1339
+ TemplateLiteral(node, _state, ancestors) {
1340
+ if (!node.quasis || node.quasis.length !== 1) return;
1341
+ if (node.expressions && node.expressions.length !== 0) return;
1342
+ if (hotExemptNodes) {
1343
+ for (let i = ancestors.length - 2; i >= 0; i--) {
1344
+ if (hotExemptNodes.has(ancestors[i])) {
1345
+ return;
1346
+ }
1347
+ }
1348
+ }
1349
+ const parent = ancestors[ancestors.length - 2];
1350
+ if (!parent) return;
1351
+ const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
1352
+ if (typeof val !== "string" || DIRECTIVE_STRINGS.has(val)) return;
1353
+ const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
1354
+ if (isShader) {
1355
+ let idx = shaderToIndex.get(val);
1356
+ if (idx === void 0) {
1357
+ idx = shaderPayloads.length;
1358
+ shaderToIndex.set(val, idx);
1359
+ shaderPayloads.push(val);
1360
+ }
1361
+ targetsToReplace.push({ type: "shader", node, parent, idx });
1362
+ } else {
1363
+ if (!shouldEncryptString(val, minStringLength)) return;
1364
+ let idx = stringToIndex.get(val);
1365
+ if (idx === void 0) {
1366
+ idx = encryptedPayloads.length;
1367
+ stringToIndex.set(val, idx);
1368
+ encryptedPayloads.push(
1369
+ encodeStringWithSeed(val, P_CHARS, expectedRot)
1370
+ );
1371
+ }
1372
+ targetsToReplace.push({ type: "string", node, parent, idx });
655
1373
  }
656
- targetsToReplace.push({ node, parent });
657
1374
  }
658
1375
  },
659
1376
  customWalkBase
660
1377
  );
661
- if (targetsToReplace.length === 0 || encryptedPayloads.length === 0) {
1378
+ if (targetsToReplace.length === 0) {
662
1379
  return {
663
1380
  encryptedStringsCount: 0,
664
- integrityToken: computeFnv1aHash("empty", seed)
1381
+ integrityToken: computeFnv1aHash("empty", seed),
1382
+ shaderBuffersCount: 0
665
1383
  };
666
1384
  }
667
1385
  const serializedTable = JSON.stringify(encryptedPayloads);
668
1386
  const integrityToken = computeFnv1aHash(serializedTable, seed);
669
- const suffix = computeFnv1aHash(`vault:${seed}`, integrityToken).toString(36);
670
- const cacheVarName = `_uC${suffix}`;
671
- for (const { node, parent } of targetsToReplace) {
1387
+ for (const { type, node, parent, idx } of targetsToReplace) {
672
1388
  if (parent?.type === "Property" && parent.key === node) {
673
1389
  parent.computed = true;
674
1390
  }
675
- const idx = stringToIndex.get(node.value);
676
- node.type = "MemberExpression";
677
- node.object = {
678
- type: "Identifier",
679
- name: cacheVarName
680
- };
681
- node.property = {
682
- type: "Literal",
683
- value: idx,
684
- raw: String(idx)
685
- };
686
- node.computed = true;
687
- node.optional = false;
688
- delete node.value;
689
- delete node.raw;
690
- }
691
- const helperStmt = createVaultHelperAst(
692
- cacheVarName,
693
- encryptedPayloads,
694
- mask,
695
- step
696
- );
1391
+ if (type === "shader") {
1392
+ node.type = "CallExpression";
1393
+ node.callee = {
1394
+ type: "Identifier",
1395
+ name: shaderVarName
1396
+ };
1397
+ node.arguments = [
1398
+ {
1399
+ type: "Literal",
1400
+ value: idx,
1401
+ raw: String(idx)
1402
+ }
1403
+ ];
1404
+ node.optional = false;
1405
+ delete node.value;
1406
+ delete node.raw;
1407
+ delete node.quasis;
1408
+ delete node.expressions;
1409
+ } else {
1410
+ node.type = "MemberExpression";
1411
+ node.object = {
1412
+ type: "Identifier",
1413
+ name: cacheVarName
1414
+ };
1415
+ node.property = {
1416
+ type: "Literal",
1417
+ value: idx,
1418
+ raw: String(idx)
1419
+ };
1420
+ node.computed = true;
1421
+ node.optional = false;
1422
+ delete node.value;
1423
+ delete node.raw;
1424
+ delete node.quasis;
1425
+ delete node.expressions;
1426
+ }
1427
+ }
697
1428
  let insertIdx = 0;
698
1429
  while (insertIdx < ast.body.length) {
699
1430
  const stmt = ast.body[insertIdx];
@@ -704,10 +1435,26 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
704
1435
  break;
705
1436
  }
706
1437
  }
707
- ast.body.splice(insertIdx, 0, helperStmt);
1438
+ if (encryptedPayloads.length > 0) {
1439
+ const vaultHelperStmt = createVaultHelperAst(
1440
+ cacheVarName,
1441
+ encryptedPayloads,
1442
+ fnAst
1443
+ );
1444
+ ast.body.splice(insertIdx++, 0, vaultHelperStmt);
1445
+ }
1446
+ if (shaderPayloads.length > 0) {
1447
+ const shaderHelperStmt = createShaderVaultAst(
1448
+ shaderVarName,
1449
+ shaderPayloads,
1450
+ seed
1451
+ );
1452
+ ast.body.splice(insertIdx++, 0, shaderHelperStmt);
1453
+ }
708
1454
  return {
709
1455
  encryptedStringsCount: encryptedPayloads.length,
710
- integrityToken
1456
+ integrityToken,
1457
+ shaderBuffersCount: shaderPayloads.length
711
1458
  };
712
1459
  }
713
1460
 
@@ -806,9 +1553,9 @@ function collectPatternTargets(pattern, out, shorthandProp) {
806
1553
  }
807
1554
  }
808
1555
  function isMangleableName(origName) {
809
- return !RESERVED_IDENTIFIERS.has(origName) && !origName.startsWith("_u") && !origName.startsWith("_0x");
1556
+ return origName.length > 2 && !RESERVED_IDENTIFIERS.has(origName) && !origName.startsWith("_u") && !origName.startsWith("_0x") && !origName.startsWith("$$");
810
1557
  }
811
- function applyPolymorphicMangler(ast, seed = 2654435769) {
1558
+ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes) {
812
1559
  const scopeRecords = /* @__PURE__ */ new Map();
813
1560
  const existingIdentifiers = /* @__PURE__ */ new Set();
814
1561
  let counter = 0;
@@ -854,11 +1601,16 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
854
1601
  }
855
1602
  return ancestors[0];
856
1603
  }
857
- function registerBindingTarget(scopeNode, target, shouldMangle) {
1604
+ function registerBindingTarget(scopeNode, target, shouldMangle, fnScope) {
858
1605
  const scope = scopeRecords.get(scopeNode);
859
1606
  if (!scope) return;
860
1607
  const origName = target.idNode.name;
861
- const canMangle = shouldMangle && isMangleableName(origName);
1608
+ let canMangle = shouldMangle && isMangleableName(origName);
1609
+ if (canMangle && fnScope) {
1610
+ if (serializedFunctionNodes && serializedFunctionNodes.has(fnScope)) {
1611
+ canMangle = false;
1612
+ }
1613
+ }
862
1614
  let entry = scope.bindings.get(origName);
863
1615
  if (!entry) {
864
1616
  entry = {
@@ -897,7 +1649,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
897
1649
  const targets = [];
898
1650
  collectPatternTargets(param, targets);
899
1651
  for (const target of targets) {
900
- registerBindingTarget(fnNode, target, true);
1652
+ registerBindingTarget(fnNode, target, true, fnNode);
901
1653
  }
902
1654
  }
903
1655
  }
@@ -967,10 +1719,11 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
967
1719
  CatchClause(node, _state, ancestors) {
968
1720
  ensureScopeChain(ancestors);
969
1721
  if (node.param) {
1722
+ const fnScope = findEnclosingFunctionNode(ancestors);
970
1723
  const targets = [];
971
1724
  collectPatternTargets(node.param, targets);
972
1725
  for (const target of targets) {
973
- registerBindingTarget(node, target, true);
1726
+ registerBindingTarget(node, target, true, fnScope);
974
1727
  }
975
1728
  }
976
1729
  },
@@ -1005,7 +1758,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
1005
1758
  }
1006
1759
  }
1007
1760
  }
1008
- registerBindingTarget(targetScopeNode, target, true);
1761
+ registerBindingTarget(targetScopeNode, target, true, fnScope);
1009
1762
  }
1010
1763
  }
1011
1764
  }
@@ -1021,12 +1774,16 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
1021
1774
  }
1022
1775
  return false;
1023
1776
  }
1777
+ const ALPHABET = "abcdefghijklmnopqrstuvwxyz";
1024
1778
  function makeScopedMangledName(scope, localIndex) {
1025
1779
  counter++;
1026
1780
  let salt = 0;
1027
1781
  while (true) {
1028
1782
  const h = computeFnv1aHash(`s${scope.depth}:i${localIndex}:${salt}`, seed);
1029
- const candidate = `_0x${((h & 31) + localIndex + salt).toString(36)}`;
1783
+ const prefix = (h & 1) === 0 ? "_" : "$";
1784
+ const ch = ALPHABET[((h >>> 1) + localIndex) % ALPHABET.length];
1785
+ const num = (localIndex + salt).toString(36);
1786
+ const candidate = `${prefix}${ch}${num}`;
1030
1787
  if (!isNameUsedInScopeOrAncestors(candidate, scope)) {
1031
1788
  return candidate;
1032
1789
  }
@@ -1136,227 +1893,420 @@ function applyPolymorphicMangler(ast, seed = 2654435769) {
1136
1893
 
1137
1894
  // src/ast/cold-flow-guard.ts
1138
1895
  import * as walk4 from "acorn-walk";
1139
- function createDecoyConsequent(fnIndex) {
1140
- const model = Math.abs(fnIndex) % 3;
1141
- if (model === 0) {
1896
+ function createDecoyObjectExpression(model) {
1897
+ const m = Math.abs(model) % 3;
1898
+ if (m === 0) {
1142
1899
  return {
1143
- type: "BlockStatement",
1144
- body: [
1900
+ type: "ObjectExpression",
1901
+ properties: [
1145
1902
  {
1146
- type: "ReturnStatement",
1147
- argument: {
1148
- type: "ObjectExpression",
1149
- properties: [
1150
- {
1151
- type: "Property",
1152
- key: { type: "Identifier", name: "endpoint" },
1153
- value: {
1154
- type: "Literal",
1155
- value: "/api/v2/auth/admin-bypass",
1156
- raw: '"/api/v2/auth/admin-bypass"'
1157
- },
1158
- kind: "init",
1159
- computed: false,
1160
- method: false,
1161
- shorthand: false
1162
- },
1163
- {
1164
- type: "Property",
1165
- key: { type: "Identifier", name: "superadmin_token" },
1166
- value: { type: "Literal", value: 1, raw: "1" },
1167
- kind: "init",
1168
- computed: false,
1169
- method: false,
1170
- shorthand: false
1171
- },
1172
- {
1173
- type: "Property",
1174
- key: { type: "Identifier", name: "elevate" },
1175
- value: { type: "Literal", value: 1, raw: "1" },
1176
- kind: "init",
1177
- computed: false,
1178
- method: false,
1179
- shorthand: false
1180
- }
1181
- ]
1182
- }
1903
+ type: "Property",
1904
+ key: { type: "Identifier", name: "endpoint" },
1905
+ value: {
1906
+ type: "Literal",
1907
+ value: "/api/v2/auth/admin-bypass",
1908
+ raw: '"/api/v2/auth/admin-bypass"'
1909
+ },
1910
+ kind: "init",
1911
+ computed: false,
1912
+ method: false,
1913
+ shorthand: false
1914
+ },
1915
+ {
1916
+ type: "Property",
1917
+ key: { type: "Identifier", name: "superadmin_token" },
1918
+ value: { type: "Literal", value: 1, raw: "1" },
1919
+ kind: "init",
1920
+ computed: false,
1921
+ method: false,
1922
+ shorthand: false
1923
+ },
1924
+ {
1925
+ type: "Property",
1926
+ key: { type: "Identifier", name: "elevate" },
1927
+ value: { type: "Literal", value: 1, raw: "1" },
1928
+ kind: "init",
1929
+ computed: false,
1930
+ method: false,
1931
+ shorthand: false
1183
1932
  }
1184
1933
  ]
1185
1934
  };
1186
1935
  }
1187
- if (model === 1) {
1936
+ if (m === 1) {
1188
1937
  return {
1189
- type: "BlockStatement",
1190
- body: [
1938
+ type: "ObjectExpression",
1939
+ properties: [
1191
1940
  {
1192
- type: "ReturnStatement",
1193
- argument: {
1194
- type: "ObjectExpression",
1195
- properties: [
1196
- {
1197
- type: "Property",
1198
- key: { type: "Identifier", name: "endpoint" },
1199
- value: {
1200
- type: "Literal",
1201
- value: "/api/v2/auth/verify-master",
1202
- raw: '"/api/v2/auth/verify-master"'
1203
- },
1204
- kind: "init",
1205
- computed: false,
1206
- method: false,
1207
- shorthand: false
1208
- },
1209
- {
1210
- type: "Property",
1211
- key: { type: "Identifier", name: "_verifyMasterToken" },
1212
- value: { type: "Literal", value: true, raw: "true" },
1213
- kind: "init",
1214
- computed: false,
1215
- method: false,
1216
- shorthand: false
1217
- },
1218
- {
1219
- type: "Property",
1220
- key: { type: "Identifier", name: "_bypassToken" },
1221
- value: {
1222
- type: "Literal",
1223
- value: "mock_jwt_bypass_signature",
1224
- raw: '"mock_jwt_bypass_signature"'
1225
- },
1226
- kind: "init",
1227
- computed: false,
1228
- method: false,
1229
- shorthand: false
1230
- },
1231
- {
1232
- type: "Property",
1233
- key: { type: "Identifier", name: "authorized" },
1234
- value: { type: "Literal", value: true, raw: "true" },
1235
- kind: "init",
1236
- computed: false,
1237
- method: false,
1238
- shorthand: false
1239
- }
1240
- ]
1241
- }
1941
+ type: "Property",
1942
+ key: { type: "Identifier", name: "endpoint" },
1943
+ value: {
1944
+ type: "Literal",
1945
+ value: "/api/v2/auth/verify-master",
1946
+ raw: '"/api/v2/auth/verify-master"'
1947
+ },
1948
+ kind: "init",
1949
+ computed: false,
1950
+ method: false,
1951
+ shorthand: false
1952
+ },
1953
+ {
1954
+ type: "Property",
1955
+ key: { type: "Identifier", name: "_verifyMasterToken" },
1956
+ value: { type: "Literal", value: true, raw: "true" },
1957
+ kind: "init",
1958
+ computed: false,
1959
+ method: false,
1960
+ shorthand: false
1961
+ },
1962
+ {
1963
+ type: "Property",
1964
+ key: { type: "Identifier", name: "_bypassToken" },
1965
+ value: {
1966
+ type: "Literal",
1967
+ value: "mock_jwt_bypass_signature",
1968
+ raw: '"mock_jwt_bypass_signature"'
1969
+ },
1970
+ kind: "init",
1971
+ computed: false,
1972
+ method: false,
1973
+ shorthand: false
1974
+ },
1975
+ {
1976
+ type: "Property",
1977
+ key: { type: "Identifier", name: "authorized" },
1978
+ value: { type: "Literal", value: true, raw: "true" },
1979
+ kind: "init",
1980
+ computed: false,
1981
+ method: false,
1982
+ shorthand: false
1242
1983
  }
1243
1984
  ]
1244
1985
  };
1245
1986
  }
1987
+ return {
1988
+ type: "ObjectExpression",
1989
+ properties: [
1990
+ {
1991
+ type: "Property",
1992
+ key: { type: "Identifier", name: "endpoint" },
1993
+ value: {
1994
+ type: "Literal",
1995
+ value: "/api/v2/auth/debug-telemetry",
1996
+ raw: '"/api/v2/auth/debug-telemetry"'
1997
+ },
1998
+ kind: "init",
1999
+ computed: false,
2000
+ method: false,
2001
+ shorthand: false
2002
+ },
2003
+ {
2004
+ type: "Property",
2005
+ key: { type: "Identifier", name: "debug_supervisor_override" },
2006
+ value: { type: "Literal", value: true, raw: "true" },
2007
+ kind: "init",
2008
+ computed: false,
2009
+ method: false,
2010
+ shorthand: false
2011
+ },
2012
+ {
2013
+ type: "Property",
2014
+ key: { type: "Identifier", name: "_bypassToken" },
2015
+ value: {
2016
+ type: "Literal",
2017
+ value: "superadmin_token",
2018
+ raw: '"superadmin_token"'
2019
+ },
2020
+ kind: "init",
2021
+ computed: false,
2022
+ method: false,
2023
+ shorthand: false
2024
+ },
2025
+ {
2026
+ type: "Property",
2027
+ key: { type: "Identifier", name: "mfa_bypassed" },
2028
+ value: { type: "Literal", value: true, raw: "true" },
2029
+ kind: "init",
2030
+ computed: false,
2031
+ method: false,
2032
+ shorthand: false
2033
+ }
2034
+ ]
2035
+ };
2036
+ }
2037
+ function createDecoyConsequent(fnIndex) {
2038
+ return {
2039
+ type: "BlockStatement",
2040
+ body: [
2041
+ {
2042
+ type: "ReturnStatement",
2043
+ argument: createDecoyObjectExpression(fnIndex)
2044
+ }
2045
+ ]
2046
+ };
2047
+ }
2048
+ function createSharedDecoyConsequent(decoyIdent, fnIndex) {
2049
+ const model = Math.abs(fnIndex) % 3;
1246
2050
  return {
1247
2051
  type: "BlockStatement",
1248
2052
  body: [
1249
2053
  {
1250
2054
  type: "ReturnStatement",
1251
2055
  argument: {
1252
- type: "ObjectExpression",
1253
- properties: [
1254
- {
1255
- type: "Property",
1256
- key: { type: "Identifier", name: "endpoint" },
1257
- value: {
1258
- type: "Literal",
1259
- value: "/api/v2/auth/debug-telemetry",
1260
- raw: '"/api/v2/auth/debug-telemetry"'
1261
- },
1262
- kind: "init",
1263
- computed: false,
1264
- method: false,
1265
- shorthand: false
1266
- },
1267
- {
1268
- type: "Property",
1269
- key: { type: "Identifier", name: "debug_supervisor_override" },
1270
- value: { type: "Literal", value: true, raw: "true" },
1271
- kind: "init",
1272
- computed: false,
1273
- method: false,
1274
- shorthand: false
1275
- },
1276
- {
1277
- type: "Property",
1278
- key: { type: "Identifier", name: "_bypassToken" },
1279
- value: {
1280
- type: "Literal",
1281
- value: "superadmin_token",
1282
- raw: '"superadmin_token"'
1283
- },
1284
- kind: "init",
1285
- computed: false,
1286
- method: false,
1287
- shorthand: false
1288
- },
1289
- {
1290
- type: "Property",
1291
- key: { type: "Identifier", name: "mfa_bypassed" },
1292
- value: { type: "Literal", value: true, raw: "true" },
1293
- kind: "init",
1294
- computed: false,
1295
- method: false,
1296
- shorthand: false
2056
+ type: "CallExpression",
2057
+ callee: {
2058
+ type: "MemberExpression",
2059
+ computed: true,
2060
+ object: { type: "Identifier", name: decoyIdent },
2061
+ property: {
2062
+ type: "Literal",
2063
+ value: model,
2064
+ raw: String(model)
1297
2065
  }
1298
- ]
2066
+ },
2067
+ arguments: []
1299
2068
  }
1300
2069
  }
1301
2070
  ]
1302
2071
  };
1303
2072
  }
1304
- function createSotaMbaPredicate(seed, fnIndex = 0) {
1305
- const x = (seed >>> 0) + Math.imul(fnIndex + 1, 73244475) | 0;
1306
- const y = x ^ 1515870810 | 0;
2073
+ function createSharedDecoyDeclaration(decoyIdent = "_d") {
2074
+ return {
2075
+ type: "VariableDeclaration",
2076
+ kind: "var",
2077
+ declarations: [
2078
+ {
2079
+ type: "VariableDeclarator",
2080
+ id: { type: "Identifier", name: decoyIdent },
2081
+ init: {
2082
+ type: "ArrayExpression",
2083
+ elements: [0, 1, 2].map((m) => ({
2084
+ type: "ArrowFunctionExpression",
2085
+ id: null,
2086
+ params: [],
2087
+ body: createDecoyObjectExpression(m),
2088
+ generator: false,
2089
+ async: false,
2090
+ expression: true
2091
+ }))
2092
+ }
2093
+ }
2094
+ ]
2095
+ };
2096
+ }
2097
+ function cloneNode(node) {
2098
+ return JSON.parse(JSON.stringify(node));
2099
+ }
2100
+ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false) {
2101
+ const family = Math.abs(seed + fnIndex & 3);
2102
+ const c1 = (seed >>> 0) + Math.imul(family + 1, 73244475) | 0;
2103
+ const c2 = c1 ^ 1515870810 | 0;
2104
+ const target = (seed ^ Math.imul(family + 1, 2654435761)) & 8388607 | 1;
2105
+ let paramName = null;
2106
+ if (typeof paramNode === "string") {
2107
+ paramName = paramNode;
2108
+ } else if (paramNode?.type === "Identifier") {
2109
+ paramName = paramNode.name;
2110
+ } else if (paramNode?.type === "AssignmentPattern" && paramNode.left?.type === "Identifier") {
2111
+ paramName = paramNode.left.name;
2112
+ }
2113
+ const zNode = {
2114
+ type: "UnaryExpression",
2115
+ operator: "+",
2116
+ prefix: true,
2117
+ argument: {
2118
+ type: "UnaryExpression",
2119
+ operator: "!",
2120
+ prefix: true,
2121
+ argument: { type: "Identifier", name: "String" }
2122
+ }
2123
+ };
2124
+ const vNode = {
2125
+ type: "BinaryExpression",
2126
+ operator: "|",
2127
+ left: zNode,
2128
+ right: { type: "Literal", value: c1, raw: String(c1) }
2129
+ };
2130
+ const kNode = {
2131
+ type: "BinaryExpression",
2132
+ operator: "|",
2133
+ left: { type: "Literal", value: c2, raw: String(c2) },
2134
+ right: {
2135
+ type: "UnaryExpression",
2136
+ operator: "!",
2137
+ prefix: true,
2138
+ argument: { type: "Identifier", name: "String" }
2139
+ }
2140
+ };
2141
+ let mbaExpr;
2142
+ if (family === 0) {
2143
+ const vXorK = {
2144
+ type: "BinaryExpression",
2145
+ operator: "^",
2146
+ left: cloneNode(vNode),
2147
+ right: cloneNode(kNode)
2148
+ };
2149
+ const vAndK = {
2150
+ type: "BinaryExpression",
2151
+ operator: "&",
2152
+ left: cloneNode(vNode),
2153
+ right: cloneNode(kNode)
2154
+ };
2155
+ const shift = {
2156
+ type: "BinaryExpression",
2157
+ operator: "<<",
2158
+ left: vAndK,
2159
+ right: { type: "Literal", value: 1, raw: "1" }
2160
+ };
2161
+ const addLeft = {
2162
+ type: "BinaryExpression",
2163
+ operator: "+",
2164
+ left: vXorK,
2165
+ right: shift
2166
+ };
2167
+ const vPlusK = {
2168
+ type: "BinaryExpression",
2169
+ operator: "+",
2170
+ left: cloneNode(vNode),
2171
+ right: cloneNode(kNode)
2172
+ };
2173
+ mbaExpr = {
2174
+ type: "BinaryExpression",
2175
+ operator: "-",
2176
+ left: addLeft,
2177
+ right: vPlusK
2178
+ };
2179
+ } else if (family === 1) {
2180
+ const vOrK = {
2181
+ type: "BinaryExpression",
2182
+ operator: "|",
2183
+ left: cloneNode(vNode),
2184
+ right: cloneNode(kNode)
2185
+ };
2186
+ const vAndK = {
2187
+ type: "BinaryExpression",
2188
+ operator: "&",
2189
+ left: cloneNode(vNode),
2190
+ right: cloneNode(kNode)
2191
+ };
2192
+ const addLeft = {
2193
+ type: "BinaryExpression",
2194
+ operator: "+",
2195
+ left: vOrK,
2196
+ right: vAndK
2197
+ };
2198
+ const vPlusK = {
2199
+ type: "BinaryExpression",
2200
+ operator: "+",
2201
+ left: cloneNode(vNode),
2202
+ right: cloneNode(kNode)
2203
+ };
2204
+ mbaExpr = {
2205
+ type: "BinaryExpression",
2206
+ operator: "^",
2207
+ left: addLeft,
2208
+ right: vPlusK
2209
+ };
2210
+ } else if (family === 2) {
2211
+ const notK = {
2212
+ type: "UnaryExpression",
2213
+ operator: "~",
2214
+ prefix: true,
2215
+ argument: cloneNode(kNode)
2216
+ };
2217
+ const vOrNotK = {
2218
+ type: "BinaryExpression",
2219
+ operator: "|",
2220
+ left: cloneNode(vNode),
2221
+ right: cloneNode(notK)
2222
+ };
2223
+ const subLeft = {
2224
+ type: "BinaryExpression",
2225
+ operator: "-",
2226
+ left: vOrNotK,
2227
+ right: cloneNode(notK)
2228
+ };
2229
+ const vAndK = {
2230
+ type: "BinaryExpression",
2231
+ operator: "&",
2232
+ left: cloneNode(vNode),
2233
+ right: cloneNode(kNode)
2234
+ };
2235
+ mbaExpr = {
2236
+ type: "BinaryExpression",
2237
+ operator: "^",
2238
+ left: subLeft,
2239
+ right: vAndK
2240
+ };
2241
+ } else {
2242
+ const notK = {
2243
+ type: "UnaryExpression",
2244
+ operator: "~",
2245
+ prefix: true,
2246
+ argument: cloneNode(kNode)
2247
+ };
2248
+ const vAndNotK = {
2249
+ type: "BinaryExpression",
2250
+ operator: "&",
2251
+ left: cloneNode(vNode),
2252
+ right: cloneNode(notK)
2253
+ };
2254
+ const vAndK = {
2255
+ type: "BinaryExpression",
2256
+ operator: "&",
2257
+ left: cloneNode(vNode),
2258
+ right: cloneNode(kNode)
2259
+ };
2260
+ const addLeft = {
2261
+ type: "BinaryExpression",
2262
+ operator: "+",
2263
+ left: vAndNotK,
2264
+ right: vAndK
2265
+ };
2266
+ mbaExpr = {
2267
+ type: "BinaryExpression",
2268
+ operator: "^",
2269
+ left: addLeft,
2270
+ right: cloneNode(vNode)
2271
+ };
2272
+ }
2273
+ const decoyIdx = Math.abs(fnIndex) % 3;
2274
+ const consequent = decoyIdent ? createSharedDecoyConsequent(decoyIdent, decoyIdx) : createDecoyConsequent(decoyIdx);
1307
2275
  return {
1308
2276
  type: "IfStatement",
1309
2277
  test: {
1310
2278
  type: "BinaryExpression",
1311
2279
  operator: "===",
1312
- left: {
1313
- type: "BinaryExpression",
1314
- operator: "|",
1315
- left: {
1316
- type: "BinaryExpression",
1317
- operator: "^",
1318
- left: {
1319
- type: "BinaryExpression",
1320
- operator: "+",
1321
- left: {
1322
- type: "BinaryExpression",
1323
- operator: "|",
1324
- left: { type: "Literal", value: x, raw: String(x) },
1325
- right: { type: "Literal", value: y, raw: String(y) }
1326
- },
1327
- right: {
1328
- type: "BinaryExpression",
1329
- operator: "&",
1330
- left: { type: "Literal", value: x, raw: String(x) },
1331
- right: { type: "Literal", value: y, raw: String(y) }
1332
- }
1333
- },
1334
- right: {
1335
- type: "BinaryExpression",
1336
- operator: "+",
1337
- left: { type: "Literal", value: x, raw: String(x) },
1338
- right: { type: "Literal", value: y, raw: String(y) }
1339
- }
1340
- },
1341
- right: {
1342
- type: "UnaryExpression",
1343
- operator: "!",
1344
- prefix: true,
1345
- argument: { type: "Identifier", name: "String" }
1346
- }
1347
- },
1348
- right: { type: "Literal", value: 2147483647, raw: "0x7fffffff" }
2280
+ left: mbaExpr,
2281
+ right: { type: "Literal", value: target, raw: String(target) }
1349
2282
  },
1350
- consequent: createDecoyConsequent(fnIndex),
2283
+ consequent,
1351
2284
  alternate: null
1352
2285
  };
1353
2286
  }
1354
2287
  function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
2288
+ const decoyIdent = "_d";
2289
+ if (Array.isArray(ast.body)) {
2290
+ const alreadyGuarded = ast.body.some(
2291
+ (stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
2292
+ (d) => d.id?.type === "Identifier" && d.id.name === decoyIdent
2293
+ )
2294
+ );
2295
+ if (alreadyGuarded) return 0;
2296
+ }
1355
2297
  let guardedCount = 0;
1356
2298
  function maybeInjectGuard(node) {
1357
2299
  if (!coldFunctionNodes.has(node)) return;
1358
2300
  if (!node.body || node.body.type !== "BlockStatement") return;
1359
- const guardStmt = createSotaMbaPredicate(seed, 0);
2301
+ const firstParam = node.params?.[0];
2302
+ const isArrow = node.type === "ArrowFunctionExpression";
2303
+ const guardStmt = createSotaMbaPredicate(
2304
+ seed,
2305
+ guardedCount,
2306
+ firstParam,
2307
+ decoyIdent,
2308
+ isArrow
2309
+ );
1360
2310
  guardedCount++;
1361
2311
  if (hotExemptNodes) {
1362
2312
  hotExemptNodes.add(guardStmt);
@@ -1373,64 +2323,946 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
1373
2323
  FunctionExpression: maybeInjectGuard,
1374
2324
  ArrowFunctionExpression: maybeInjectGuard
1375
2325
  });
2326
+ if (guardedCount > 0 && Array.isArray(ast.body)) {
2327
+ const sharedDecoyDecl = createSharedDecoyDeclaration(decoyIdent);
2328
+ if (hotExemptNodes) {
2329
+ hotExemptNodes.add(sharedDecoyDecl);
2330
+ for (const decl of sharedDecoyDecl.declarations || []) {
2331
+ if (decl.init?.elements) {
2332
+ for (const el of decl.init.elements) {
2333
+ hotExemptNodes.add(el);
2334
+ }
2335
+ }
2336
+ }
2337
+ }
2338
+ let insertIdx = 0;
2339
+ while (insertIdx < ast.body.length && ast.body[insertIdx].type === "ExpressionStatement" && ast.body[insertIdx].directive) {
2340
+ insertIdx++;
2341
+ }
2342
+ ast.body.splice(insertIdx, 0, sharedDecoyDecl);
2343
+ }
1376
2344
  return guardedCount;
1377
2345
  }
1378
2346
 
1379
- // src/runtime/integrity-guard.ts
1380
- var FNV_OFFSET_BASIS = 2166136261;
1381
- var FNV_PRIME = 16777619;
1382
- function computeIntegrityHash(source, seed = 0) {
1383
- let hash = (FNV_OFFSET_BASIS ^ seed >>> 0) >>> 0;
1384
- for (let i = 0; i < source.length; i++) {
1385
- hash ^= source.charCodeAt(i);
1386
- hash = Math.imul(hash, FNV_PRIME) >>> 0;
2347
+ // src/ast/micro-vm.ts
2348
+ import * as acorn3 from "acorn";
2349
+ import * as walk5 from "acorn-walk";
2350
+ var OP_LDC = 0;
2351
+ var OP_LDV = 1;
2352
+ var OP_STV = 2;
2353
+ var OP_LDG = 3;
2354
+ var OP_GETP = 4;
2355
+ var OP_SETP = 5;
2356
+ var OP_CALL = 6;
2357
+ var OP_MCALL = 7;
2358
+ var OP_ADD = 8;
2359
+ var OP_SUB = 9;
2360
+ var OP_MUL = 10;
2361
+ var OP_XOR = 11;
2362
+ var OP_AND = 12;
2363
+ var OP_OR = 13;
2364
+ var OP_SEQ = 14;
2365
+ var OP_LT = 15;
2366
+ var OP_NOT = 16;
2367
+ var OP_JMP = 17;
2368
+ var OP_JZ = 18;
2369
+ var OP_RET = 19;
2370
+ var OP_THROW = 20;
2371
+ var OP_AWAIT = 21;
2372
+ var OP_OBJ = 22;
2373
+ var OP_ARR = 23;
2374
+ function generateOpcodeMap(seed) {
2375
+ const pool = [];
2376
+ for (let i = 0; i < 256; i++) pool.push(i);
2377
+ let s = (seed ^ 2779096485) >>> 0;
2378
+ function rand() {
2379
+ s ^= s << 13;
2380
+ s ^= s >>> 17;
2381
+ s ^= s << 5;
2382
+ return (s >>> 0) / 4294967296;
1387
2383
  }
1388
- return hash >>> 0;
2384
+ for (let i = pool.length - 1; i > 0; i--) {
2385
+ const j = Math.floor(rand() * (i + 1));
2386
+ const tmp = pool[i];
2387
+ pool[i] = pool[j];
2388
+ pool[j] = tmp;
2389
+ }
2390
+ return pool.slice(0, 24);
1389
2391
  }
1390
-
1391
- // src/runtime/devtools-deterrent.ts
1392
- function deriveIntegrityFnName(seed) {
1393
- const hash = computeIntegrityHash(`unpeek:fn:${seed}`, seed);
1394
- return `_u$${hash.toString(36)}`;
2392
+ function createInterpreterSource(vmHelperName, opMap) {
2393
+ return `function ${vmHelperName}(c, k, s, t) {
2394
+ var p = 0, r = 0, q = [];
2395
+ var G = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this);
2396
+ function x() {
2397
+ while (p < c.length) {
2398
+ var o = c[p++];
2399
+ switch (o) {
2400
+ case ${opMap[OP_LDC]}: q[r++] = k[c[p++]]; break;
2401
+ case ${opMap[OP_LDV]}: q[r++] = s[c[p++]]; break;
2402
+ case ${opMap[OP_STV]}: s[c[p++]] = q[--r]; break;
2403
+ case ${opMap[OP_LDG]}: q[r++] = G[k[c[p++]]]; break;
2404
+ case ${opMap[OP_GETP]}: { var b = q[--r], a = q[--r]; q[r++] = a[b]; break; }
2405
+ case ${opMap[OP_SETP]}: { var v = q[--r], b = q[--r], a = q[--r]; q[r++] = (a[b] = v); break; }
2406
+ case ${opMap[OP_CALL]}: {
2407
+ var n = c[p++], g = [];
2408
+ for (var i = n - 1; i >= 0; i--) g[i] = q[--r];
2409
+ var f = q[--r]; q[r++] = f.apply(null, g); break;
2410
+ }
2411
+ case ${opMap[OP_MCALL]}: {
2412
+ var n = c[p++], g = [];
2413
+ for (var i = n - 1; i >= 0; i--) g[i] = q[--r];
2414
+ var b = q[--r], a = q[--r]; q[r++] = a[b].apply(a, g); break;
2415
+ }
2416
+ case ${opMap[OP_ADD]}: { var b = q[--r], a = q[--r]; q[r++] = a + b; break; }
2417
+ case ${opMap[OP_SUB]}: { var b = q[--r], a = q[--r]; q[r++] = a - b; break; }
2418
+ case ${opMap[OP_MUL]}: { var b = q[--r], a = q[--r]; q[r++] = a * b; break; }
2419
+ case ${opMap[OP_XOR]}: { var b = q[--r], a = q[--r]; q[r++] = a ^ b; break; }
2420
+ case ${opMap[OP_AND]}: { var b = q[--r], a = q[--r]; q[r++] = a & b; break; }
2421
+ case ${opMap[OP_OR]}: { var b = q[--r], a = q[--r]; q[r++] = a | b; break; }
2422
+ case ${opMap[OP_SEQ]}: { var b = q[--r], a = q[--r]; q[r++] = a === b; break; }
2423
+ case ${opMap[OP_LT]}: { var b = q[--r], a = q[--r]; q[r++] = a < b; break; }
2424
+ case ${opMap[OP_NOT]}: { q[r - 1] = !q[r - 1]; break; }
2425
+ case ${opMap[OP_JMP]}: { p = c[p]; break; }
2426
+ case ${opMap[OP_JZ]}: { var j = c[p++]; if (!q[--r]) p = j; break; }
2427
+ case ${opMap[OP_RET]}: return q[--r];
2428
+ case ${opMap[OP_THROW]}: throw q[--r];
2429
+ case ${opMap[OP_AWAIT]}: {
2430
+ var v = q[--r];
2431
+ return Promise.resolve(v).then(function(w) { q[r++] = w; return x(); });
2432
+ }
2433
+ case ${opMap[OP_OBJ]}: {
2434
+ var n = c[p++], o = {}, e = [];
2435
+ for (var i = 0; i < n; i++) { var v = q[--r], k0 = q[--r]; e.push([k0, v]); }
2436
+ for (var i = e.length - 1; i >= 0; i--) { o[e[i][0]] = e[i][1]; }
2437
+ q[r++] = o;
2438
+ break;
2439
+ }
2440
+ case ${opMap[OP_ARR]}: {
2441
+ var n = c[p++], a = [];
2442
+ for (var i = n - 1; i >= 0; i--) a[i] = q[--r];
2443
+ q[r++] = a;
2444
+ break;
2445
+ }
2446
+ }
2447
+ }
2448
+ }
2449
+ return x();
2450
+ }`;
1395
2451
  }
1396
- function createDeterrentSnippet(config) {
1397
- const seed = config.seed >>> 0;
1398
- const deterrentMode = config.deterrentMode ?? "passive";
1399
- const fnName = deriveIntegrityFnName(seed);
1400
- const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=f=>0;" : "";
1401
- return `(function ${fnName}(w){if(w){try{(w.queueMicrotask||w.requestIdleCallback||(f=>f()))(function f(a){var s=Function.prototype.toString,n=w.navigator||0,t=s.call(s).indexOf('[native code]')<0||/\\n/.test(s.call(${fnName}))||n.webdriver||/HeadlessChrome/.test(n.userAgent);if(t){w.__unpeek_tampered=!0,w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0,String.prototype._u=14;try{${consoleSilence}w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}});}catch(e){}}})(typeof window!=='undefined'&&window);`;
2452
+ function countAstNodes(node) {
2453
+ let count = 0;
2454
+ walk5.full(node, () => {
2455
+ count++;
2456
+ });
2457
+ return count;
2458
+ }
2459
+ function hasForbiddenConstructs(fnNode) {
2460
+ let forbidden = false;
2461
+ walk5.full(fnNode, (node) => {
2462
+ if (forbidden) return;
2463
+ const type = node.type;
2464
+ if (type === "JSXElement" || type === "JSXFragment" || type === "Super" || type === "YieldExpression") {
2465
+ forbidden = true;
2466
+ return;
2467
+ }
2468
+ if (type === "Identifier" && node.name === "arguments") {
2469
+ forbidden = true;
2470
+ return;
2471
+ }
2472
+ if (type === "MetaProperty" && node.meta?.name === "new" && node.property?.name === "target") {
2473
+ forbidden = true;
2474
+ return;
2475
+ }
2476
+ });
2477
+ return forbidden;
2478
+ }
2479
+ function compileFunctionToBytecode(fnNode, opMap) {
2480
+ const bytecode = [];
2481
+ const consts = [];
2482
+ const localMap = /* @__PURE__ */ new Map();
2483
+ let localCount = 0;
2484
+ for (const param of fnNode.params) {
2485
+ if (param.type !== "Identifier") return null;
2486
+ localMap.set(param.name, localCount++);
2487
+ }
2488
+ const bodyNodes = fnNode.body.type === "BlockStatement" ? fnNode.body.body : [fnNode.body];
2489
+ for (const stmt of bodyNodes) {
2490
+ if (stmt.type === "VariableDeclaration") {
2491
+ for (const decl of stmt.declarations) {
2492
+ if (decl.id.type === "Identifier") {
2493
+ if (!localMap.has(decl.id.name)) {
2494
+ localMap.set(decl.id.name, localCount++);
2495
+ }
2496
+ } else {
2497
+ return null;
2498
+ }
2499
+ }
2500
+ }
2501
+ }
2502
+ function addConst(val) {
2503
+ for (let i = 0; i < consts.length; i++) {
2504
+ if (consts[i] === val) return i;
2505
+ }
2506
+ const idx = consts.length;
2507
+ consts.push(val);
2508
+ return idx;
2509
+ }
2510
+ function emit(op, ...args) {
2511
+ bytecode.push(opMap[op]);
2512
+ for (const a of args) bytecode.push(a);
2513
+ }
2514
+ function compileExpr(node) {
2515
+ if (!node) return false;
2516
+ switch (node.type) {
2517
+ case "Literal": {
2518
+ const idx = addConst(node.value);
2519
+ emit(OP_LDC, idx);
2520
+ return true;
2521
+ }
2522
+ case "Identifier": {
2523
+ if (node.name === "undefined") {
2524
+ const idx = addConst(void 0);
2525
+ emit(OP_LDC, idx);
2526
+ } else if (localMap.has(node.name)) {
2527
+ emit(OP_LDV, localMap.get(node.name));
2528
+ } else {
2529
+ const idx = addConst(node.name);
2530
+ emit(OP_LDG, idx);
2531
+ }
2532
+ return true;
2533
+ }
2534
+ case "BinaryExpression": {
2535
+ if (node.operator === ">") {
2536
+ if (!compileExpr(node.right)) return false;
2537
+ if (!compileExpr(node.left)) return false;
2538
+ emit(OP_LT);
2539
+ return true;
2540
+ }
2541
+ if (node.operator === "<=") {
2542
+ if (!compileExpr(node.right)) return false;
2543
+ if (!compileExpr(node.left)) return false;
2544
+ emit(OP_LT);
2545
+ emit(OP_NOT);
2546
+ return true;
2547
+ }
2548
+ if (node.operator === ">=") {
2549
+ if (!compileExpr(node.left)) return false;
2550
+ if (!compileExpr(node.right)) return false;
2551
+ emit(OP_LT);
2552
+ emit(OP_NOT);
2553
+ return true;
2554
+ }
2555
+ if (!compileExpr(node.left)) return false;
2556
+ if (!compileExpr(node.right)) return false;
2557
+ switch (node.operator) {
2558
+ case "+":
2559
+ emit(OP_ADD);
2560
+ break;
2561
+ case "-":
2562
+ emit(OP_SUB);
2563
+ break;
2564
+ case "*":
2565
+ emit(OP_MUL);
2566
+ break;
2567
+ case "^":
2568
+ emit(OP_XOR);
2569
+ break;
2570
+ case "&":
2571
+ emit(OP_AND);
2572
+ break;
2573
+ case "|":
2574
+ emit(OP_OR);
2575
+ break;
2576
+ case "==":
2577
+ case "===":
2578
+ emit(OP_SEQ);
2579
+ break;
2580
+ case "!=":
2581
+ case "!==":
2582
+ emit(OP_SEQ);
2583
+ emit(OP_NOT);
2584
+ break;
2585
+ case "<":
2586
+ emit(OP_LT);
2587
+ break;
2588
+ default:
2589
+ return false;
2590
+ }
2591
+ return true;
2592
+ }
2593
+ case "UnaryExpression": {
2594
+ if (!compileExpr(node.argument)) return false;
2595
+ switch (node.operator) {
2596
+ case "!":
2597
+ emit(OP_NOT);
2598
+ break;
2599
+ case "-": {
2600
+ const neg1Idx = addConst(-1);
2601
+ emit(OP_LDC, neg1Idx);
2602
+ emit(OP_MUL);
2603
+ break;
2604
+ }
2605
+ case "+": {
2606
+ const zeroIdx = addConst(0);
2607
+ emit(OP_LDC, zeroIdx);
2608
+ emit(OP_ADD);
2609
+ break;
2610
+ }
2611
+ case "~": {
2612
+ const neg1Idx = addConst(-1);
2613
+ emit(OP_LDC, neg1Idx);
2614
+ emit(OP_XOR);
2615
+ break;
2616
+ }
2617
+ case "void": {
2618
+ const undefIdx2 = addConst(void 0);
2619
+ emit(OP_LDC, undefIdx2);
2620
+ break;
2621
+ }
2622
+ default:
2623
+ return false;
2624
+ }
2625
+ return true;
2626
+ }
2627
+ case "MemberExpression": {
2628
+ if (!compileExpr(node.object)) return false;
2629
+ if (node.computed) {
2630
+ if (!compileExpr(node.property)) return false;
2631
+ } else {
2632
+ const idx = addConst(node.property.name);
2633
+ emit(OP_LDC, idx);
2634
+ }
2635
+ emit(OP_GETP);
2636
+ return true;
2637
+ }
2638
+ case "CallExpression": {
2639
+ if (node.callee.type === "MemberExpression") {
2640
+ if (!compileExpr(node.callee.object)) return false;
2641
+ if (node.callee.computed) {
2642
+ if (!compileExpr(node.callee.property)) return false;
2643
+ } else {
2644
+ const idx = addConst(node.callee.property.name);
2645
+ emit(OP_LDC, idx);
2646
+ }
2647
+ for (const arg of node.arguments) {
2648
+ if (!compileExpr(arg)) return false;
2649
+ }
2650
+ emit(OP_MCALL, node.arguments.length);
2651
+ } else {
2652
+ if (!compileExpr(node.callee)) return false;
2653
+ for (const arg of node.arguments) {
2654
+ if (!compileExpr(arg)) return false;
2655
+ }
2656
+ emit(OP_CALL, node.arguments.length);
2657
+ }
2658
+ return true;
2659
+ }
2660
+ case "AssignmentExpression": {
2661
+ if (node.operator !== "=") return false;
2662
+ if (node.left.type === "Identifier") {
2663
+ if (!localMap.has(node.left.name)) return false;
2664
+ if (!compileExpr(node.right)) return false;
2665
+ emit(OP_STV, localMap.get(node.left.name));
2666
+ return true;
2667
+ }
2668
+ if (node.left.type === "MemberExpression") {
2669
+ if (!compileExpr(node.left.object)) return false;
2670
+ if (node.left.computed) {
2671
+ if (!compileExpr(node.left.property)) return false;
2672
+ } else {
2673
+ const idx = addConst(node.left.property.name);
2674
+ emit(OP_LDC, idx);
2675
+ }
2676
+ if (!compileExpr(node.right)) return false;
2677
+ emit(OP_SETP);
2678
+ return true;
2679
+ }
2680
+ return false;
2681
+ }
2682
+ case "ObjectExpression": {
2683
+ for (const prop of node.properties) {
2684
+ if (prop.type !== "Property") return false;
2685
+ if (prop.computed) {
2686
+ if (!compileExpr(prop.key)) return false;
2687
+ } else {
2688
+ const keyName = prop.key.name ?? prop.key.value;
2689
+ const idx = addConst(keyName);
2690
+ emit(OP_LDC, idx);
2691
+ }
2692
+ if (!compileExpr(prop.value)) return false;
2693
+ }
2694
+ emit(OP_OBJ, node.properties.length);
2695
+ return true;
2696
+ }
2697
+ case "ArrayExpression": {
2698
+ for (const elem of node.elements) {
2699
+ if (!compileExpr(elem)) return false;
2700
+ }
2701
+ emit(OP_ARR, node.elements.length);
2702
+ return true;
2703
+ }
2704
+ case "AwaitExpression": {
2705
+ if (!compileExpr(node.argument)) return false;
2706
+ emit(OP_AWAIT);
2707
+ return true;
2708
+ }
2709
+ default:
2710
+ return false;
2711
+ }
2712
+ }
2713
+ function compileStmt(stmt) {
2714
+ if (!stmt) return false;
2715
+ switch (stmt.type) {
2716
+ case "ReturnStatement": {
2717
+ if (stmt.argument) {
2718
+ if (!compileExpr(stmt.argument)) return false;
2719
+ } else {
2720
+ const idx = addConst(void 0);
2721
+ emit(OP_LDC, idx);
2722
+ }
2723
+ emit(OP_RET);
2724
+ return true;
2725
+ }
2726
+ case "ExpressionStatement": {
2727
+ if (!compileExpr(stmt.expression)) return false;
2728
+ return true;
2729
+ }
2730
+ case "VariableDeclaration": {
2731
+ for (const decl of stmt.declarations) {
2732
+ if (decl.init) {
2733
+ if (!compileExpr(decl.init)) return false;
2734
+ emit(OP_STV, localMap.get(decl.id.name));
2735
+ }
2736
+ }
2737
+ return true;
2738
+ }
2739
+ case "IfStatement": {
2740
+ if (!compileExpr(stmt.test)) return false;
2741
+ const jzPos = bytecode.length;
2742
+ emit(OP_JZ, 0);
2743
+ if (!compileStmt(stmt.consequent)) return false;
2744
+ if (stmt.alternate) {
2745
+ const jmpPos = bytecode.length;
2746
+ emit(OP_JMP, 0);
2747
+ bytecode[jzPos + 1] = bytecode.length;
2748
+ if (!compileStmt(stmt.alternate)) return false;
2749
+ bytecode[jmpPos + 1] = bytecode.length;
2750
+ } else {
2751
+ bytecode[jzPos + 1] = bytecode.length;
2752
+ }
2753
+ return true;
2754
+ }
2755
+ case "BlockStatement": {
2756
+ for (const s of stmt.body) {
2757
+ if (!compileStmt(s)) return false;
2758
+ }
2759
+ return true;
2760
+ }
2761
+ default:
2762
+ return false;
2763
+ }
2764
+ }
2765
+ if (fnNode.body.type === "BlockStatement") {
2766
+ if (!compileStmt(fnNode.body)) return null;
2767
+ } else {
2768
+ if (!compileExpr(fnNode.body)) return null;
2769
+ emit(OP_RET);
2770
+ }
2771
+ const undefIdx = addConst(void 0);
2772
+ emit(OP_LDC, undefIdx);
2773
+ emit(OP_RET);
2774
+ return { bytecode, consts, localCount };
2775
+ }
2776
+ function isMicroVmAlreadyInjected(ast) {
2777
+ if (!ast || !Array.isArray(ast.body)) return false;
2778
+ return ast.body.some((stmt) => {
2779
+ if (stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")) {
2780
+ return true;
2781
+ }
2782
+ return false;
2783
+ });
2784
+ }
2785
+ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769) {
2786
+ const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
2787
+ const vmHelperName = `_uVm${suffix}`;
2788
+ if (isMicroVmAlreadyInjected(ast)) {
2789
+ const existing = ast.body.find(
2790
+ (stmt) => stmt.type === "FunctionDeclaration" && typeof stmt.id?.name === "string" && stmt.id.name.startsWith("_uVm")
2791
+ );
2792
+ return {
2793
+ virtualizedCount: 0,
2794
+ vmHelperName: existing?.id?.name ?? vmHelperName
2795
+ };
2796
+ }
2797
+ const opMap = generateOpcodeMap(seed);
2798
+ const candidates = [];
2799
+ walk5.simple(ast, {
2800
+ FunctionDeclaration(node) {
2801
+ candidates.push(node);
2802
+ },
2803
+ FunctionExpression(node) {
2804
+ candidates.push(node);
2805
+ },
2806
+ ArrowFunctionExpression(node) {
2807
+ candidates.push(node);
2808
+ }
2809
+ });
2810
+ let virtualizedCount = 0;
2811
+ for (const fn of candidates) {
2812
+ if (virtualizedCount >= 10) break;
2813
+ if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
2814
+ continue;
2815
+ }
2816
+ if (serializedFunctionNodes && serializedFunctionNodes.has(fn)) {
2817
+ continue;
2818
+ }
2819
+ if (fn.generator) {
2820
+ continue;
2821
+ }
2822
+ if (hasForbiddenConstructs(fn)) {
2823
+ continue;
2824
+ }
2825
+ const nodeCount = countAstNodes(fn);
2826
+ if (nodeCount < 15 || nodeCount > 80) {
2827
+ continue;
2828
+ }
2829
+ const compiled = compileFunctionToBytecode(fn, opMap);
2830
+ if (!compiled) {
2831
+ continue;
2832
+ }
2833
+ const paramArgs = fn.params.map((p) => ({
2834
+ type: "Identifier",
2835
+ name: p.name
2836
+ }));
2837
+ const callExpr = {
2838
+ type: "CallExpression",
2839
+ callee: {
2840
+ type: "Identifier",
2841
+ name: vmHelperName
2842
+ },
2843
+ arguments: [
2844
+ {
2845
+ type: "ArrayExpression",
2846
+ elements: compiled.bytecode.map((b) => ({
2847
+ type: "Literal",
2848
+ value: b,
2849
+ raw: String(b)
2850
+ }))
2851
+ },
2852
+ {
2853
+ type: "ArrayExpression",
2854
+ elements: compiled.consts.map((c) => ({
2855
+ type: "Literal",
2856
+ value: c,
2857
+ raw: c === void 0 ? "void 0" : JSON.stringify(c)
2858
+ }))
2859
+ },
2860
+ {
2861
+ type: "ArrayExpression",
2862
+ elements: paramArgs
2863
+ },
2864
+ {
2865
+ type: "ThisExpression"
2866
+ }
2867
+ ],
2868
+ optional: false
2869
+ };
2870
+ if (fn.body.type === "BlockStatement") {
2871
+ fn.body.body = [
2872
+ {
2873
+ type: "ReturnStatement",
2874
+ argument: callExpr
2875
+ }
2876
+ ];
2877
+ } else {
2878
+ fn.body = callExpr;
2879
+ }
2880
+ virtualizedCount++;
2881
+ }
2882
+ if (virtualizedCount > 0) {
2883
+ const interpreterSource = createInterpreterSource(vmHelperName, opMap);
2884
+ const parsedHelper = acorn3.parse(interpreterSource, {
2885
+ ecmaVersion: "latest",
2886
+ sourceType: "script"
2887
+ });
2888
+ ast.body.unshift(...parsedHelper.body);
2889
+ }
2890
+ return {
2891
+ virtualizedCount,
2892
+ vmHelperName
2893
+ };
1402
2894
  }
1403
2895
 
1404
- // src/runtime/index.ts
1405
- function generateRuntimeShield(config) {
1406
- const preambleCode = createDeterrentSnippet(config);
1407
- const integrityCheckFnName = deriveIntegrityFnName(config.seed);
1408
- const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computeIntegrityHash(preambleCode, config.seed);
2896
+ // src/ast/wasm-vault.ts
2897
+ import * as acorn4 from "acorn";
2898
+ function encodeSignedLeb128(value) {
2899
+ const bytes = [];
2900
+ let val = value | 0;
2901
+ let more = true;
2902
+ while (more) {
2903
+ let byte = val & 127;
2904
+ val >>= 7;
2905
+ if (val === 0 && (byte & 64) === 0 || val === -1 && (byte & 64) !== 0) {
2906
+ more = false;
2907
+ } else {
2908
+ byte |= 128;
2909
+ }
2910
+ bytes.push(byte);
2911
+ }
2912
+ return bytes;
2913
+ }
2914
+ function encodeUnsignedLeb128(value) {
2915
+ const bytes = [];
2916
+ let val = value >>> 0;
2917
+ do {
2918
+ let byte = val & 127;
2919
+ val >>>= 7;
2920
+ if (val !== 0) {
2921
+ byte |= 128;
2922
+ }
2923
+ bytes.push(byte);
2924
+ } while (val !== 0);
2925
+ return bytes;
2926
+ }
2927
+ function generateWasmKdfBinary(seed) {
2928
+ const instructions = [
2929
+ 32,
2930
+ 0,
2931
+ // local.get 0
2932
+ 65,
2933
+ ...encodeSignedLeb128(seed),
2934
+ // i32.const seed
2935
+ 115,
2936
+ // i32.xor
2937
+ 65,
2938
+ ...encodeSignedLeb128(16777619),
2939
+ // i32.const 0x01000193
2940
+ 108,
2941
+ // i32.mul
2942
+ 32,
2943
+ 1,
2944
+ // local.get 1
2945
+ 32,
2946
+ 2,
2947
+ // local.get 2
2948
+ 106,
2949
+ // i32.add
2950
+ 65,
2951
+ ...encodeSignedLeb128(73244475),
2952
+ // i32.const 0x45d9f3b
2953
+ 108,
2954
+ // i32.mul
2955
+ 115,
2956
+ // i32.xor
2957
+ 11
2958
+ // end
2959
+ ];
2960
+ const funcBody = [0, ...instructions];
2961
+ const funcBodyWithLen = [...encodeUnsignedLeb128(funcBody.length), ...funcBody];
2962
+ const codeSectionPayload = [1, ...funcBodyWithLen];
2963
+ const codeSection = [
2964
+ 10,
2965
+ ...encodeUnsignedLeb128(codeSectionPayload.length),
2966
+ ...codeSectionPayload
2967
+ ];
2968
+ const typePayload = [
2969
+ 1,
2970
+ // 1 type
2971
+ 96,
2972
+ // func
2973
+ 3,
2974
+ 127,
2975
+ 127,
2976
+ 127,
2977
+ // 3 params of type i32
2978
+ 1,
2979
+ 127
2980
+ // 1 result of type i32
2981
+ ];
2982
+ const typeSection = [
2983
+ 1,
2984
+ ...encodeUnsignedLeb128(typePayload.length),
2985
+ ...typePayload
2986
+ ];
2987
+ const funcPayload = [
2988
+ 1,
2989
+ // 1 function
2990
+ 0
2991
+ // type index 0
2992
+ ];
2993
+ const funcSection = [
2994
+ 3,
2995
+ ...encodeUnsignedLeb128(funcPayload.length),
2996
+ ...funcPayload
2997
+ ];
2998
+ const exportName = [3, 107, 100, 102];
2999
+ const exportPayload = [
3000
+ 1,
3001
+ // 1 export
3002
+ ...exportName,
3003
+ 0,
3004
+ // function export
3005
+ 0
3006
+ // function index 0
3007
+ ];
3008
+ const exportSection = [
3009
+ 7,
3010
+ ...encodeUnsignedLeb128(exportPayload.length),
3011
+ ...exportPayload
3012
+ ];
3013
+ const header = [0, 97, 115, 109, 1, 0, 0, 0];
3014
+ return new Uint8Array([
3015
+ ...header,
3016
+ ...typeSection,
3017
+ ...funcSection,
3018
+ ...exportSection,
3019
+ ...codeSection
3020
+ ]);
3021
+ }
3022
+ function fallbackKdf(fnId, callSiteSalt, shieldHash, seed) {
3023
+ return Math.imul(fnId ^ seed | 0, 16777619) ^ Math.imul(callSiteSalt + shieldHash | 0, 73244475) | 0;
3024
+ }
3025
+ function isWasmVaultAlreadyInjected(ast) {
3026
+ if (!ast || !Array.isArray(ast.body)) return false;
3027
+ return ast.body.some((stmt) => {
3028
+ if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
3029
+ (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
3030
+ )) {
3031
+ return true;
3032
+ }
3033
+ return false;
3034
+ });
3035
+ }
3036
+ function injectWasmVault(ast, seed = 2654435769) {
3037
+ const suffix = computeFnv1aHash(`wasm:${seed}`, seed).toString(36);
3038
+ const kdfFnName = `_wKdf${suffix}`;
3039
+ const wasmVarName = `_wb${suffix}`;
3040
+ if (isWasmVaultAlreadyInjected(ast)) {
3041
+ const existing = ast.body.find(
3042
+ (stmt) => stmt.type === "VariableDeclaration" && stmt.declarations?.some(
3043
+ (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_wKdf")
3044
+ )
3045
+ );
3046
+ const id = existing?.declarations[0]?.id?.name ?? kdfFnName;
3047
+ return {
3048
+ kdfFnName: id,
3049
+ wasmBytes: generateWasmKdfBinary(seed),
3050
+ wasmVarName
3051
+ };
3052
+ }
3053
+ const wasmBytes = generateWasmKdfBinary(seed);
3054
+ const byteArrayLiteral = Array.from(wasmBytes).join(",");
3055
+ const helperSnippet = `var ${kdfFnName};
3056
+ try {
3057
+ var ${wasmVarName} = new Uint8Array([${byteArrayLiteral}]);
3058
+ var _wm${suffix} = new WebAssembly.Module(${wasmVarName});
3059
+ var _wi${suffix} = new WebAssembly.Instance(_wm${suffix});
3060
+ ${kdfFnName} = _wi${suffix}.exports.kdf;
3061
+ } catch (e) {
3062
+ ${kdfFnName} = function(f, s, h) {
3063
+ return (Math.imul((f ^ ${seed | 0}) | 0, 16777619) ^ Math.imul(((s + h) | 0), 73244475)) | 0;
3064
+ };
3065
+ }`;
3066
+ const parsedHelper = acorn4.parse(helperSnippet, {
3067
+ ecmaVersion: "latest",
3068
+ sourceType: "script"
3069
+ });
3070
+ ast.body.unshift(...parsedHelper.body);
1409
3071
  return {
1410
- preambleCode,
1411
- integrityCheckFnName,
1412
- expectedHash
3072
+ kdfFnName,
3073
+ wasmBytes,
3074
+ wasmVarName
1413
3075
  };
1414
3076
  }
1415
3077
 
1416
- // src/ast/index.ts
1417
- function isAstAlreadyProtected(ast) {
3078
+ // src/ast/salted-vault.ts
3079
+ import * as acorn5 from "acorn";
3080
+ import * as walk6 from "acorn-walk";
3081
+ var DIRECTIVE_STRINGS2 = /* @__PURE__ */ new Set([
3082
+ "use strict",
3083
+ "use client",
3084
+ "use server",
3085
+ "use asm"
3086
+ ]);
3087
+ function encodeSaltedString(str, k) {
3088
+ let out = "";
3089
+ for (let j = 0; j < str.length; j++) {
3090
+ const code = str.charCodeAt(j);
3091
+ const mask = k >>> j % 24 & 127 | 1;
3092
+ out += String.fromCharCode(code ^ mask);
3093
+ }
3094
+ return out;
3095
+ }
3096
+ function isAstAlreadySalted(ast) {
1418
3097
  if (!ast || !Array.isArray(ast.body)) return false;
1419
3098
  return ast.body.some((stmt) => {
1420
3099
  if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
1421
- (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uC")
3100
+ (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
1422
3101
  )) {
1423
3102
  return true;
1424
3103
  }
1425
- if (stmt.type === "ExpressionStatement" && stmt.expression?.type === "CallExpression" && stmt.expression.callee?.type === "FunctionExpression" && typeof stmt.expression.callee.id?.name === "string" && stmt.expression.callee.id.name.startsWith("_u$")) {
3104
+ return false;
3105
+ });
3106
+ }
3107
+ function replaceNodeInParent(parent, oldNode, newNode) {
3108
+ if (!parent) return false;
3109
+ for (const key of Object.keys(parent)) {
3110
+ const val = parent[key];
3111
+ if (val === oldNode) {
3112
+ parent[key] = newNode;
1426
3113
  return true;
1427
3114
  }
3115
+ if (Array.isArray(val)) {
3116
+ const idx = val.indexOf(oldNode);
3117
+ if (idx !== -1) {
3118
+ val[idx] = newNode;
3119
+ return true;
3120
+ }
3121
+ }
3122
+ }
3123
+ return false;
3124
+ }
3125
+ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
3126
+ if (isAstAlreadySalted(ast)) {
3127
+ return {
3128
+ encryptedStringsCount: 0,
3129
+ integrityToken: computeFnv1aHash("already-salted", seed),
3130
+ vaultVarName: "",
3131
+ decryptFnName: ""
3132
+ };
3133
+ }
3134
+ const targetsToReplace = [];
3135
+ const encryptedPayloads = [];
3136
+ walk6.ancestor(ast, {
3137
+ Literal(node, ancestors) {
3138
+ if (typeof node.value !== "string") return;
3139
+ if (node.value.length < minStringLength) return;
3140
+ if (DIRECTIVE_STRINGS2.has(node.value)) return;
3141
+ const parent = ancestors[ancestors.length - 2];
3142
+ if (!parent) return;
3143
+ if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration") && parent.source === node) {
3144
+ return;
3145
+ }
3146
+ if (parent.type === "Property" && parent.key === node && !parent.computed) {
3147
+ return;
3148
+ }
3149
+ if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
3150
+ return;
3151
+ }
3152
+ if (hotExemptNodes) {
3153
+ for (let i = ancestors.length - 1; i >= 0; i--) {
3154
+ if (hotExemptNodes.has(ancestors[i])) {
3155
+ return;
3156
+ }
3157
+ }
3158
+ }
3159
+ const callSiteIdx = targetsToReplace.length;
3160
+ const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
3161
+ targetsToReplace.push({
3162
+ node,
3163
+ parent,
3164
+ callSiteIdx,
3165
+ localSalt,
3166
+ rawString: node.value
3167
+ });
3168
+ }
3169
+ });
3170
+ if (targetsToReplace.length === 0) {
3171
+ return {
3172
+ encryptedStringsCount: 0,
3173
+ integrityToken: computeFnv1aHash("empty-salted", seed),
3174
+ vaultVarName: "",
3175
+ decryptFnName: ""
3176
+ };
3177
+ }
3178
+ const wasmResult = injectWasmVault(ast, seed);
3179
+ const kdfFnName = wasmResult.kdfFnName;
3180
+ const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
3181
+ const vaultVarName = `_uP${suffix}`;
3182
+ const cacheVarName = `_uCache${suffix}`;
3183
+ const decryptFnName = `_uD${suffix}`;
3184
+ for (const target of targetsToReplace) {
3185
+ const k = fallbackKdf(target.callSiteIdx, target.localSalt, 0, seed);
3186
+ encryptedPayloads.push(encodeSaltedString(target.rawString, k));
3187
+ const callExpr = {
3188
+ type: "CallExpression",
3189
+ callee: {
3190
+ type: "Identifier",
3191
+ name: decryptFnName
3192
+ },
3193
+ arguments: [
3194
+ {
3195
+ type: "Literal",
3196
+ value: target.callSiteIdx,
3197
+ raw: String(target.callSiteIdx)
3198
+ },
3199
+ {
3200
+ type: "Literal",
3201
+ value: target.localSalt,
3202
+ raw: String(target.localSalt)
3203
+ }
3204
+ ],
3205
+ optional: false
3206
+ };
3207
+ replaceNodeInParent(target.parent, target.node, callExpr);
3208
+ }
3209
+ const serializedTable = JSON.stringify(encryptedPayloads);
3210
+ const integrityToken = computeFnv1aHash(serializedTable, seed);
3211
+ const helperSnippet = `var ${vaultVarName} = ${serializedTable};
3212
+ var ${cacheVarName} = [];
3213
+ function ${decryptFnName}(i, s) {
3214
+ if (${cacheVarName}[i] !== void 0) return ${cacheVarName}[i];
3215
+ var d = typeof window !== 'undefined' && window.__unpeek_delta != null ? window.__unpeek_delta : 0;
3216
+ var k = ${kdfFnName}(i, s, d);
3217
+ var p = ${vaultVarName}[i], o = '';
3218
+ for (var j = 0; j < p.length; j++) {
3219
+ o += String.fromCharCode(p.charCodeAt(j) ^ (((k >>> (j % 24)) & 127) | 1));
3220
+ }
3221
+ return (${cacheVarName}[i] = o);
3222
+ }`;
3223
+ const parsedHelper = acorn5.parse(helperSnippet, {
3224
+ ecmaVersion: "latest",
3225
+ sourceType: "script"
3226
+ });
3227
+ ast.body.unshift(...parsedHelper.body);
3228
+ return {
3229
+ encryptedStringsCount: targetsToReplace.length,
3230
+ integrityToken,
3231
+ vaultVarName,
3232
+ decryptFnName
3233
+ };
3234
+ }
3235
+
3236
+ // src/ast/index.ts
3237
+ function isAstAlreadyProtected(ast) {
3238
+ if (!ast || !Array.isArray(ast.body)) return false;
3239
+ return ast.body.some((stmt) => {
3240
+ if (stmt.type === "VariableDeclaration" && Array.isArray(stmt.declarations)) {
3241
+ for (const d of stmt.declarations) {
3242
+ const name = d.id?.name;
3243
+ if (typeof name === "string") {
3244
+ if (name === "_d" || name.startsWith("_uC") || name.startsWith("_uD") || name.startsWith("_uS") || name.startsWith("_uVm") || name.startsWith("_wKdf") || name.startsWith("_m") || name.startsWith("_w") || name.startsWith("_k") || name.startsWith("_a") && d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f") {
3245
+ return true;
3246
+ }
3247
+ }
3248
+ }
3249
+ }
3250
+ if (stmt.type === "ExpressionStatement" && stmt.expression?.type === "CallExpression") {
3251
+ const callee = stmt.expression.callee;
3252
+ if (callee?.type === "FunctionExpression") {
3253
+ const name = callee.id?.name;
3254
+ if (typeof name === "string" && (name.startsWith("_u$") || name.startsWith("_$") || name.startsWith("_s") || name.startsWith("$b"))) {
3255
+ return true;
3256
+ }
3257
+ }
3258
+ }
1428
3259
  return false;
1429
3260
  });
1430
3261
  }
1431
3262
  function transformJavaScript(code, options = {}) {
1432
3263
  const seed = options.seed ?? 2654435769;
1433
3264
  const minStringLength = options.minStringLength ?? 4;
3265
+ const isAggressive = options.aggressive ?? false;
1434
3266
  if (!code || !code.trim()) {
1435
3267
  return {
1436
3268
  code,
@@ -1441,7 +3273,9 @@ function transformJavaScript(code, options = {}) {
1441
3273
  hotFunctionsSkipped: [],
1442
3274
  coldFunctionsProtected: []
1443
3275
  },
1444
- integrityToken: computeFnv1aHash("", seed)
3276
+ integrityToken: computeFnv1aHash("", seed),
3277
+ virtualizedFunctionsCount: 0,
3278
+ shaderBuffersCount: 0
1445
3279
  };
1446
3280
  }
1447
3281
  const ast = parseJavaScriptAst(code);
@@ -1455,23 +3289,59 @@ function transformJavaScript(code, options = {}) {
1455
3289
  hotFunctionsSkipped: [],
1456
3290
  coldFunctionsProtected: []
1457
3291
  },
1458
- integrityToken: computeFnv1aHash(code, seed)
3292
+ integrityToken: computeFnv1aHash(code, seed),
3293
+ virtualizedFunctionsCount: 0,
3294
+ shaderBuffersCount: 0
1459
3295
  };
1460
3296
  }
1461
3297
  const {
1462
3298
  report: hotPathReport,
1463
3299
  coldFunctionNodes,
1464
- hotExemptNodes
3300
+ hotFunctionNodes,
3301
+ hotExemptNodes,
3302
+ serializedFunctionNodes
1465
3303
  } = analyzeAstHotPaths(ast);
3304
+ let virtualizedFunctionsCount = 0;
3305
+ if (isAggressive) {
3306
+ const vmRes = applyMicroVm(
3307
+ ast,
3308
+ coldFunctionNodes,
3309
+ serializedFunctionNodes,
3310
+ seed
3311
+ );
3312
+ virtualizedFunctionsCount = vmRes.virtualizedCount;
3313
+ }
1466
3314
  applyColdFlowGuard(ast, coldFunctionNodes, seed, hotExemptNodes);
1467
- const mangledSymbolsCount = applyPolymorphicMangler(ast, seed);
1468
- const { encryptedStringsCount, integrityToken } = applyStringVault(
3315
+ const mangledSymbolsCount = applyPolymorphicMangler(
1469
3316
  ast,
1470
3317
  seed,
1471
- minStringLength,
1472
- hotExemptNodes
3318
+ serializedFunctionNodes
1473
3319
  );
1474
- const outputCode = generate(ast, { indent: "", lineEnd: "" });
3320
+ let encryptedStringsCount = 0;
3321
+ let integrityToken = 0;
3322
+ let shaderBuffersCount = 0;
3323
+ if (isAggressive) {
3324
+ injectWasmVault(ast, seed);
3325
+ const saltedRes = applySaltedStringVault(
3326
+ ast,
3327
+ seed,
3328
+ minStringLength,
3329
+ hotExemptNodes
3330
+ );
3331
+ encryptedStringsCount = saltedRes.encryptedStringsCount;
3332
+ integrityToken = saltedRes.integrityToken;
3333
+ } else {
3334
+ const vaultRes = applyStringVault(
3335
+ ast,
3336
+ seed,
3337
+ minStringLength,
3338
+ hotExemptNodes
3339
+ );
3340
+ encryptedStringsCount = vaultRes.encryptedStringsCount;
3341
+ integrityToken = vaultRes.integrityToken;
3342
+ shaderBuffersCount = vaultRes.shaderBuffersCount ?? 0;
3343
+ }
3344
+ const outputCode = generateCompactJs(ast);
1475
3345
  let finalCode = outputCode;
1476
3346
  if (options.injectRuntimeShield) {
1477
3347
  const shield = generateRuntimeShield({
@@ -1489,7 +3359,9 @@ ${finalCode}`;
1489
3359
  encryptedStringsCount,
1490
3360
  mangledSymbolsCount,
1491
3361
  hotPathReport,
1492
- integrityToken
3362
+ integrityToken,
3363
+ virtualizedFunctionsCount,
3364
+ shaderBuffersCount
1493
3365
  };
1494
3366
  }
1495
3367
 
@@ -1499,6 +3371,7 @@ var unpeekPlugin = createUnplugin((options = {}) => {
1499
3371
  const deterrentMode = options.deterrentMode ?? "gradual";
1500
3372
  const injectRuntimeShield = options.injectRuntimeShield ?? true;
1501
3373
  const minStringLength = options.minStringLength ?? 4;
3374
+ const aggressive = options.aggressive ?? false;
1502
3375
  return {
1503
3376
  name: "unpeek",
1504
3377
  enforce: "post",
@@ -1516,7 +3389,8 @@ var unpeekPlugin = createUnplugin((options = {}) => {
1516
3389
  minStringLength,
1517
3390
  filename: chunk.fileName,
1518
3391
  injectRuntimeShield: shouldInjectShield,
1519
- deterrentMode
3392
+ deterrentMode,
3393
+ aggressive
1520
3394
  });
1521
3395
  let finalCode = result.code;
1522
3396
  if (shouldInjectShield) {