@anonympins/fingerprint 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anonympins/fingerprint",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "An HTTP(S) client mitigation and anti-bot protection library for Node.js/Express, based on digital fingerprinting and dynamic Proof-of-Work (PoW) challenges.",
5
5
  "main": "fingerprint.js",
6
6
  "type": "module",
package/pow.solver.js CHANGED
@@ -16,7 +16,9 @@
16
16
  * @returns {Promise<number>} La solution (un nombre entier).
17
17
  */
18
18
  export async function solveCpuTargetInline(clientIp, nonce, target, clientSecret = null, progressCallback) {
19
- const cpuTarget = BigInt('0x' + target);
19
+ // Le 'target' est déjà un BigInt lorsqu'il est appelé depuis la page de challenge.
20
+ // On s'assure juste qu'il est bien de ce type.
21
+ const cpuTarget = typeof target === 'bigint' ? target : BigInt('0x' + target);
20
22
  let cpuSolution = 0;
21
23
  const ipPart = clientIp || ''; // Use empty string if IP is null/undefined
22
24
  while (true) { // When a clientSecret is used, the IP is omitted from the hash to make it independent of the network.
@@ -77,18 +79,28 @@ export async function solveCpuTarget(message, target) {
77
79
  * @returns {Promise<number>} La solution (nombre entier).
78
80
  */
79
81
  export async function solveMemory(seed, difficulty) {
82
+ // On définit un seuil pour savoir quand faire une pause, afin de ne pas bloquer le thread UI.
83
+ const YIELD_THRESHOLD = 100000;
80
84
  const size = difficulty * 1024 * 1024;
81
85
  const buffer = new Uint32Array(size / 4);
82
86
  let h = new TextEncoder().encode(seed).reduce((acc, v) => acc + v, 0);
87
+
83
88
  for (let i = 0; i < buffer.length; i++) {
84
89
  buffer[i] = (h = Math.imul(h ^ i, 1597334677));
90
+ if (i % YIELD_THRESHOLD === 0) {
91
+ await new Promise(r => setTimeout(r, 0)); // Respiration pour ne pas geler l'UI
92
+ }
85
93
  }
94
+
86
95
  let solution = 0;
87
96
  const iterations = size / 16;
88
97
  let addr = buffer.length > 0 ? buffer[0] % buffer.length : 0;
89
98
  for (let i = 0; i < iterations; i++) {
90
99
  addr = buffer[addr] % buffer.length;
91
100
  solution ^= addr;
101
+ if (i % YIELD_THRESHOLD === 0) {
102
+ await new Promise(r => setTimeout(r, 0)); // Respiration pour ne pas geler l'UI
103
+ }
92
104
  }
93
105
  return solution;
94
106
  }