altcha-lib 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/README.md CHANGED
@@ -4,7 +4,7 @@ ALTCHA JS Library is a lightweight, zero-dependency library designed for creatin
4
4
 
5
5
  ## Compatibility
6
6
 
7
- This library utilizes [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) and is intended for server-side use.
7
+ This library utilizes [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) and can be used in modern browsers and supported server environments:
8
8
 
9
9
  - Node.js 16+
10
10
  - Bun 1+
@@ -103,16 +103,18 @@ const solution = await solveChallengeWorkers(
103
103
 
104
104
  ```
105
105
  > solveChallenge()
106
- - n = 1,000............................... 317 ops/s ±2.63%
107
- - n = 10,000.............................. 32 ops/s ±1.88%
108
- - n = 100,000............................. 3 ops/s ±0.34%
109
- - n = 500,000............................. 0 ops/s ±0.32%
106
+ - n = 1,000............................... 319 ops/s ±2.04%
107
+ - n = 10,000.............................. 31 ops/s ±1.02%
108
+ - n = 50,000.............................. 6 ops/s ±1.48%
109
+ - n = 100,000............................. 3 ops/s ±0.27%
110
+ - n = 500,000............................. 0 ops/s ±0.36%
110
111
 
111
112
  > solveChallengeWorkers() (8 workers)
112
- - n = 1,000............................... 66 ops/s ±3.44%
113
- - n = 10,000.............................. 31 ops/s ±4.28%
114
- - n = 100,000............................. 7 ops/s ±4.40%
115
- - n = 500,000............................. 1 ops/s ±2.49%
113
+ - n = 1,000............................... 62 ops/s ±5.69%
114
+ - n = 10,000.............................. 30 ops/s ±4.35%
115
+ - n = 50,000.............................. 12 ops/s ±2.89%
116
+ - n = 100,000............................. 7 ops/s ±2.33%
117
+ - n = 500,000............................. 1 ops/s ±2.22%
116
118
  ```
117
119
 
118
120
  Run with Bun on MacBook Pro M3-Pro. See [/benchmark](/benchmark/) folder for more details.
@@ -5,4 +5,4 @@ export declare function solveChallenge(challenge: string, salt: string, algorith
5
5
  promise: Promise<Solution | null>;
6
6
  controller: AbortController;
7
7
  };
8
- export declare function solveChallengeWorkers(workerScript: string | URL, concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
8
+ export declare function solveChallengeWorkers(workerScript: string | URL | (() => Worker), concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
package/cjs/dist/index.js CHANGED
@@ -76,9 +76,14 @@ async function solveChallengeWorkers(workerScript, concurrency, challenge, salt,
76
76
  throw new Error('Too many workers. Max. 16 allowed workers.');
77
77
  }
78
78
  for (let i = 0; i < concurrency; i++) {
79
- workers.push(new Worker(workerScript, {
80
- type: 'module',
81
- }));
79
+ if (typeof workerScript === 'function') {
80
+ workers.push(workerScript());
81
+ }
82
+ else {
83
+ workers.push(new Worker(workerScript, {
84
+ type: 'module',
85
+ }));
86
+ }
82
87
  }
83
88
  const step = Math.ceil(max / concurrency);
84
89
  const solutions = await Promise.all(workers.map((worker, i) => {
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export declare function solveChallenge(challenge: string, salt: string, algorith
5
5
  promise: Promise<Solution | null>;
6
6
  controller: AbortController;
7
7
  };
8
- export declare function solveChallengeWorkers(workerScript: string | URL, concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
8
+ export declare function solveChallengeWorkers(workerScript: string | URL | (() => Worker), concurrency: number, challenge: string, salt: string, algorithm?: string, max?: number, startNumber?: number): Promise<Solution | null>;
package/dist/index.js CHANGED
@@ -70,9 +70,14 @@ export async function solveChallengeWorkers(workerScript, concurrency, challenge
70
70
  throw new Error('Too many workers. Max. 16 allowed workers.');
71
71
  }
72
72
  for (let i = 0; i < concurrency; i++) {
73
- workers.push(new Worker(workerScript, {
74
- type: 'module',
75
- }));
73
+ if (typeof workerScript === 'function') {
74
+ workers.push(workerScript());
75
+ }
76
+ else {
77
+ workers.push(new Worker(workerScript, {
78
+ type: 'module',
79
+ }));
80
+ }
76
81
  }
77
82
  const step = Math.ceil(max / concurrency);
78
83
  const solutions = await Promise.all(workers.map((worker, i) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "altcha-lib",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A library for creating and verifying ALTCHA challenges for Node.js, Bun and Deno.",
5
5
  "author": "Daniel Regeci",
6
6
  "license": "MIT",