@anonympins/fingerprint 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -793,8 +793,16 @@
793
793
  ]
794
794
  ]
795
795
  ];
796
- $decision['body'] = $challengePayload;
797
- return $decision;
796
+ if ($isApiRequest) {
797
+ $decision['body'] = $challengePayload;
798
+ return $decision;
799
+ } else {
800
+ $html = '<html><body><script>';
801
+ $html .= 'window.location.href = "' . $context->path . '?pow_type=useful_work_task&pow_nonce=' . $nonce . '&pow_problem_id=' . $work['problemId'] . '&pow_solution_work_result=" + encodeURIComponent(JSON.stringify({"solution": [], "energy": 0}));';
802
+ $html .= '</script></body></html>';
803
+ $decision['body'] = $html;
804
+ return $decision;
805
+ }
798
806
  } else {
799
807
  // This case handles when uPoW is enabled but dispatching a task fails (e.g., config not found).
800
808
  // We log it and fall through to the standard PoW challenge.
@@ -1,63 +1,64 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Anonympins\Fingerprint\Optimization;
6
-
7
- /**
8
- * Registre pour exposer de manière contrôlée les fonctions de la bibliothèque d'optimisation.
9
- */
10
- class FunctionRegistry
11
- {
12
- /** @var array<string, callable> */
13
- private static array $functions = [];
14
-
15
- /**
16
- * Initialise le registre avec les fonctions disponibles.
17
- */
18
- private static function initialize(): void
19
- {
20
- if (empty(self::$functions)) {
21
- // Fonctions de "Scoring"
22
- self::$functions['tsp.calculateEnergy'] = [OptimizationUtils::class, 'evaluatePathDistance'];
23
- self::$functions['portfolio.calculateMetrics'] = [OptimizationOperators::class, 'createPortfolioAllocator'];
24
-
25
- // Fonctions de "Résolution"
26
- self::$functions['tsp.solve'] = [OptimizationOperators::class, 'solveTSP'];
27
- self::$functions['portfolio.solve'] = [OptimizationOperators::class, 'solvePortfolio'];
28
- self::$functions['fraud.solve'] = [OptimizationOperators::class, 'solveFraudDetection'];
29
- self::$functions['facility.solve'] = [OptimizationOperators::class, 'solveFacilityLocation'];
30
- self::$functions['security.tune'] = [OptimizationOperators::class, 'solveFullSecurityTuning'];
31
- }
32
- }
33
-
34
- /**
35
- * Récupère une fonction depuis le registre.
36
- */
37
- public static function get(string $name): ?callable
38
- {
39
- self::initialize();
40
- return self::$functions[$name] ?? null;
41
- }
42
- /**
43
- * Enregistre une nouvelle fonction. Principalement pour les tests.
44
- * @internal
45
- * @param string $name
46
- * @param callable $function
47
- * @return void
48
- */
49
- public static function register(string $name, callable $function): void
50
- {
51
- self::initialize();
52
- self::$functions[$name] = $function;
53
- }
54
-
55
- /**
56
- * Réinitialise le registre. Uniquement pour les tests.
57
- * @internal
58
- */
59
- public static function __internal_resetRegistry(): void
60
- {
61
- self::$functions = [];
62
- }
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ namespace Anonympins\Fingerprint\Optimization;
6
+
7
+ /**
8
+ * Registre pour exposer de manière contrôlée les fonctions de la bibliothèque d'optimisation.
9
+ */
10
+ class FunctionRegistry
11
+ {
12
+ /** @var array<string, callable> */
13
+ private static array $functions = [];
14
+
15
+ /**
16
+ * Initialise le registre avec les fonctions disponibles.
17
+ */
18
+ private static function initialize(): void
19
+ {
20
+ if (empty(self::$functions)) {
21
+ // Fonctions de "Scoring"
22
+ self::$functions['tsp.calculateEnergy'] = [OptimizationUtils::class, 'evaluatePathDistance'];
23
+ self::$functions['portfolio.calculateMetrics'] = [OptimizationOperators::class, 'createPortfolioAllocator'];
24
+ self::$functions['facility.calculateEnergy'] = [OptimizationOperators::class, 'evaluateFacilityLocation'];
25
+
26
+ // Fonctions de "Résolution"
27
+ self::$functions['tsp.solve'] = [OptimizationOperators::class, 'solveTSP'];
28
+ self::$functions['portfolio.solve'] = [OptimizationOperators::class, 'solvePortfolio'];
29
+ self::$functions['fraud.solve'] = [OptimizationOperators::class, 'solveFraudDetection'];
30
+ self::$functions['facility.solve'] = [OptimizationOperators::class, 'solveFacilityLocation'];
31
+ self::$functions['security.tune'] = [OptimizationOperators::class, 'solveFullSecurityTuning'];
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Récupère une fonction depuis le registre.
37
+ */
38
+ public static function get(string $name): ?callable
39
+ {
40
+ self::initialize();
41
+ return self::$functions[$name] ?? null;
42
+ }
43
+ /**
44
+ * Enregistre une nouvelle fonction. Principalement pour les tests.
45
+ * @internal
46
+ * @param string $name
47
+ * @param callable $function
48
+ * @return void
49
+ */
50
+ public static function register(string $name, callable $function): void
51
+ {
52
+ self::initialize();
53
+ self::$functions[$name] = $function;
54
+ }
55
+
56
+ /**
57
+ * Réinitialise le registre. Uniquement pour les tests.
58
+ * @internal
59
+ */
60
+ public static function __internal_resetRegistry(): void
61
+ {
62
+ self::$functions = [];
63
+ }
63
64
  }