@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.
- package/CHANGELOG.md +17 -0
- package/README.md +66 -60
- package/package.json +1 -1
- package/src/js/fingerprint.js +10 -2
- package/src/js/pow.solver.js +531 -497
- package/src/js/problem-manager.js +24 -0
- package/src/js/tests/fingerprint.test.js +2351 -2319
- package/src/js/tests/pow.solver.test.js +233 -197
- package/src/js/tests/problem-manager.test.js +358 -322
- package/src/php/FingerprintEngine.php +10 -2
- package/src/php/Optimization/FunctionRegistry.php +63 -62
- package/src/php/Optimization/OptimizationOperators.php +401 -304
- package/src/php/ProblemManager.php +29 -0
- package/src/php/Tests/FingerprintEngineTest.php +330 -299
- package/src/php/Tests/ProblemManagerTest.php +376 -296
- package/src/php/Tests/RequestUtilsTest.php +256 -253
- package/src/php/Tests/problems.config.json +3 -3
- package/src/php/Utils/RequestUtils.php +1 -1
|
@@ -793,8 +793,16 @@
|
|
|
793
793
|
]
|
|
794
794
|
]
|
|
795
795
|
];
|
|
796
|
-
$
|
|
797
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
self::$functions['
|
|
28
|
-
self::$functions['
|
|
29
|
-
self::$functions['
|
|
30
|
-
self::$functions['
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
* @param
|
|
47
|
-
* @
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
self
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
}
|