altcha-lib 2.0.0-beta.1 → 2.0.0-beta.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.
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ If your framework is not listed, see the [Advanced Usage](/docs/advanced-usage.m
|
|
|
21
21
|
- Advanced Usage: [`/docs/advanced-usage.md`](/docs/advanced-usage.md)
|
|
22
22
|
- Algorithms: [`/docs/algorithms.md`](/docs/algorithms.md)
|
|
23
23
|
- Configuration Options: [`/docs/configuration-options.md`](/docs/configuration-options.md)
|
|
24
|
+
- Obfuscation: [`/docs/obfuscation.md`](/docs/obfuscation.md)
|
|
24
25
|
- Store: [`/docs/store.md`](/docs/store.md)
|
|
25
26
|
- Usage with ALTCHA Sentinel: [`/docs/server-signatures.md`](/docs/server-signatures.md)
|
|
26
27
|
- Using the `/verify` Route: [`/docs/verify-route.md`](/docs/verify-route.md)
|
|
@@ -6,7 +6,7 @@ const pbkdf2_js_1 = require("./algorithms/pbkdf2.js");
|
|
|
6
6
|
const pow_js_1 = require("./pow.js");
|
|
7
7
|
const helpers_js_1 = require("./helpers.js");
|
|
8
8
|
async function deobfuscate(obfuscatedData, options = {}) {
|
|
9
|
-
const { concurrency = navigator.hardwareConcurrency, createWorker, deriveKey = pbkdf2_js_1.deriveKey, } = options;
|
|
9
|
+
const { concurrency = Math.max(1, Math.min(4, typeof navigator !== 'undefined' ? navigator.hardwareConcurrency : 1)), createWorker, deriveKey = pbkdf2_js_1.deriveKey, } = options;
|
|
10
10
|
let challenge = null;
|
|
11
11
|
try {
|
|
12
12
|
challenge = JSON.parse(atob(obfuscatedData));
|
package/dist/cjs/v2/pow.js
CHANGED
|
@@ -124,7 +124,7 @@ async function solveChallenge(options) {
|
|
|
124
124
|
* Automatically retries with fewer workers on out-of-memory errors.
|
|
125
125
|
*/
|
|
126
126
|
async function solveChallengeWorkers(options) {
|
|
127
|
-
const { challenge, concurrency = navigator.hardwareConcurrency, controller = new AbortController(), createWorker, onOutOfMemory = (c) => (c > 1 ? Math.floor(c / 2) : 0), counterMode, } = options;
|
|
127
|
+
const { challenge, concurrency = navigator.hardwareConcurrency, controller = new AbortController(), createWorker, onOutOfMemory = (c) => (c > 1 ? Math.floor(c / 2) : 0), counterMode, timeout, } = options;
|
|
128
128
|
const workersConcurrency = Math.min(16, Math.max(1, concurrency));
|
|
129
129
|
const workersInstances = [];
|
|
130
130
|
const terminate = () => {
|
|
@@ -166,6 +166,7 @@ async function solveChallengeWorkers(options) {
|
|
|
166
166
|
counterMode,
|
|
167
167
|
counterStart: i,
|
|
168
168
|
counterStep: workersConcurrency,
|
|
169
|
+
timeout,
|
|
169
170
|
type: 'work',
|
|
170
171
|
});
|
|
171
172
|
});
|
|
@@ -6,7 +6,7 @@ function handler(options) {
|
|
|
6
6
|
const { deriveKey } = options;
|
|
7
7
|
let controller = undefined;
|
|
8
8
|
self.onmessage = async (message) => {
|
|
9
|
-
const { challenge, counterMode, counterStart, counterStep, type } = message.data;
|
|
9
|
+
const { challenge, counterMode, counterStart, counterStep, timeout, type } = message.data;
|
|
10
10
|
if (type === 'abort') {
|
|
11
11
|
controller?.abort();
|
|
12
12
|
}
|
|
@@ -21,6 +21,7 @@ function handler(options) {
|
|
|
21
21
|
counterStep,
|
|
22
22
|
deriveKey,
|
|
23
23
|
counterMode,
|
|
24
|
+
timeout,
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
catch (err) {
|
|
@@ -2,7 +2,7 @@ import { deriveKey as derivedKeyPBKDF2 } from './algorithms/pbkdf2.js';
|
|
|
2
2
|
import { createChallenge, solveChallenge, solveChallengeWorkers, } from './pow.js';
|
|
3
3
|
import { bufferToHex, hexToBuffer } from './helpers.js';
|
|
4
4
|
export async function deobfuscate(obfuscatedData, options = {}) {
|
|
5
|
-
const { concurrency = navigator.hardwareConcurrency, createWorker, deriveKey = derivedKeyPBKDF2, } = options;
|
|
5
|
+
const { concurrency = Math.max(1, Math.min(4, typeof navigator !== 'undefined' ? navigator.hardwareConcurrency : 1)), createWorker, deriveKey = derivedKeyPBKDF2, } = options;
|
|
6
6
|
let challenge = null;
|
|
7
7
|
try {
|
|
8
8
|
challenge = JSON.parse(atob(obfuscatedData));
|
package/dist/esm/v2/pow.js
CHANGED
|
@@ -119,7 +119,7 @@ export async function solveChallenge(options) {
|
|
|
119
119
|
* Automatically retries with fewer workers on out-of-memory errors.
|
|
120
120
|
*/
|
|
121
121
|
export async function solveChallengeWorkers(options) {
|
|
122
|
-
const { challenge, concurrency = navigator.hardwareConcurrency, controller = new AbortController(), createWorker, onOutOfMemory = (c) => (c > 1 ? Math.floor(c / 2) : 0), counterMode, } = options;
|
|
122
|
+
const { challenge, concurrency = navigator.hardwareConcurrency, controller = new AbortController(), createWorker, onOutOfMemory = (c) => (c > 1 ? Math.floor(c / 2) : 0), counterMode, timeout, } = options;
|
|
123
123
|
const workersConcurrency = Math.min(16, Math.max(1, concurrency));
|
|
124
124
|
const workersInstances = [];
|
|
125
125
|
const terminate = () => {
|
|
@@ -161,6 +161,7 @@ export async function solveChallengeWorkers(options) {
|
|
|
161
161
|
counterMode,
|
|
162
162
|
counterStart: i,
|
|
163
163
|
counterStep: workersConcurrency,
|
|
164
|
+
timeout,
|
|
164
165
|
type: 'work',
|
|
165
166
|
});
|
|
166
167
|
});
|
|
@@ -3,7 +3,7 @@ export function handler(options) {
|
|
|
3
3
|
const { deriveKey } = options;
|
|
4
4
|
let controller = undefined;
|
|
5
5
|
self.onmessage = async (message) => {
|
|
6
|
-
const { challenge, counterMode, counterStart, counterStep, type } = message.data;
|
|
6
|
+
const { challenge, counterMode, counterStart, counterStep, timeout, type } = message.data;
|
|
7
7
|
if (type === 'abort') {
|
|
8
8
|
controller?.abort();
|
|
9
9
|
}
|
|
@@ -18,6 +18,7 @@ export function handler(options) {
|
|
|
18
18
|
counterStep,
|
|
19
19
|
deriveKey,
|
|
20
20
|
counterMode,
|
|
21
|
+
timeout,
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "altcha-lib",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "A lightweight library for creating and verifying ALTCHA challenges on the server.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Daniel Regeci",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"prepare": "husky"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
|
+
"bin",
|
|
33
34
|
"dist"
|
|
34
35
|
],
|
|
35
36
|
"bin": {
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
"express": "^5.2.1",
|
|
113
114
|
"fastify": "^5.8.2",
|
|
114
115
|
"globals": "^17.4.0",
|
|
115
|
-
"h3": "2.0.1-rc.
|
|
116
|
+
"h3": "^2.0.1-rc.18",
|
|
116
117
|
"hono": "^4.12.5",
|
|
117
118
|
"husky": "^9.1.7",
|
|
118
119
|
"prettier": "^3.8.1",
|