@anonympins/fingerprint 0.1.2 → 0.1.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/README.md +44 -0
- package/fingerprint.client.js +4 -4
- package/fingerprint.js +2339 -2267
- package/package.json +1 -1
- package/pow.solver.js +19 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anonympins/fingerprint",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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,12 +16,13 @@
|
|
|
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(target);
|
|
19
|
+
const cpuTarget = BigInt('0x' + target);
|
|
20
20
|
let cpuSolution = 0;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const ipPart = clientIp || ''; // Use empty string if IP is null/undefined
|
|
22
|
+
while (true) { // When a clientSecret is used, the IP is omitted from the hash to make it independent of the network.
|
|
23
|
+
const msg = clientSecret ?
|
|
24
|
+
`${nonce}:${cpuSolution}:${clientSecret}` :
|
|
25
|
+
`${ipPart}:${nonce}:${cpuSolution}`;
|
|
25
26
|
const buf = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(msg));
|
|
26
27
|
const hashHex = Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
27
28
|
if (BigInt('0x' + hashHex) < cpuTarget) break;
|
|
@@ -162,12 +163,16 @@ export async function solveTsp(cities, targetMaxDistance) {
|
|
|
162
163
|
* @returns {Promise<object>} Un objet contenant la ou les solutions.
|
|
163
164
|
*/
|
|
164
165
|
export async function solveChallenge(challenge) {
|
|
165
|
-
const { type, nonce, clientSecret,
|
|
166
|
+
const { type, nonce, clientSecret, cpuTarget, memDifficulty, cities, clientIp, targetMaxDistance } = challenge;
|
|
166
167
|
const solutions = {};
|
|
167
168
|
|
|
168
169
|
switch (type) {
|
|
169
170
|
case 'cpu_target':
|
|
170
171
|
const baseMessageCpu = `:${nonce}`; // L'IP est gérée côté serveur
|
|
172
|
+
if (!cpuTarget) {
|
|
173
|
+
throw new Error("Challenge data is missing 'cpuTarget' property.");
|
|
174
|
+
}
|
|
175
|
+
const target = cpuTarget; // Keep variable name for consistency below
|
|
171
176
|
solutions.cpu = await solveCpuTarget(baseMessageCpu, BigInt('0x' + target));
|
|
172
177
|
break;
|
|
173
178
|
case 'cpu_mem':
|
|
@@ -175,8 +180,10 @@ export async function solveChallenge(challenge) {
|
|
|
175
180
|
const baseMessageCombined = `${nonce}:${clientSecret}`;
|
|
176
181
|
const memSeed = `:${nonce}:${clientSecret}`;
|
|
177
182
|
const [cpuSol, memSol] = await Promise.all([
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
(async () => {
|
|
184
|
+
if (!cpuTarget) throw new Error("Challenge data is missing 'cpuTarget' property.");
|
|
185
|
+
return solveCpuTargetInline(null, nonce, cpuTarget, clientSecret);
|
|
186
|
+
})(),
|
|
180
187
|
solveMemory(memSeed, memDifficulty)
|
|
181
188
|
]);
|
|
182
189
|
solutions.cpu = cpuSol;
|
|
@@ -186,7 +193,10 @@ export async function solveChallenge(challenge) {
|
|
|
186
193
|
// Version inline pour compatibilité HTML avec IP incluse
|
|
187
194
|
const memSeedInline = `${nonce}:${clientSecret}`;
|
|
188
195
|
const [cpuSolInline, memSolInline] = await Promise.all([
|
|
189
|
-
|
|
196
|
+
(async () => {
|
|
197
|
+
if (!cpuTarget) throw new Error("Challenge data is missing 'cpuTarget' property.");
|
|
198
|
+
return solveCpuTargetInline(clientIp, nonce, cpuTarget, clientSecret);
|
|
199
|
+
})(),
|
|
190
200
|
solveMemory(memSeedInline, memDifficulty)
|
|
191
201
|
]);
|
|
192
202
|
solutions.cpu = cpuSolInline;
|