altcha-lib 0.1.3 → 0.1.5

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.
@@ -5,4 +5,11 @@ 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>;
9
+ declare const _default: {
10
+ createChallenge: typeof createChallenge;
11
+ verifySolution: typeof verifySolution;
12
+ solveChallenge: typeof solveChallenge;
13
+ solveChallengeWorkers: typeof solveChallengeWorkers;
14
+ };
15
+ export default _default;
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) => {
@@ -115,3 +120,9 @@ exports.solveChallengeWorkers = solveChallengeWorkers;
115
120
  async function hashChallenge(salt, num, algorithm) {
116
121
  return (0, helpers_js_1.ab2hex)(await crypto.subtle.digest(algorithm.toUpperCase(), helpers_js_1.encoder.encode(salt + num)));
117
122
  }
123
+ exports.default = {
124
+ createChallenge,
125
+ verifySolution,
126
+ solveChallenge,
127
+ solveChallengeWorkers,
128
+ };
package/dist/index.d.ts CHANGED
@@ -5,4 +5,11 @@ 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>;
9
+ declare const _default: {
10
+ createChallenge: typeof createChallenge;
11
+ verifySolution: typeof verifySolution;
12
+ solveChallenge: typeof solveChallenge;
13
+ solveChallengeWorkers: typeof solveChallengeWorkers;
14
+ };
15
+ export default _default;
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) => {
@@ -108,3 +113,9 @@ export async function solveChallengeWorkers(workerScript, concurrency, challenge
108
113
  async function hashChallenge(salt, num, algorithm) {
109
114
  return ab2hex(await crypto.subtle.digest(algorithm.toUpperCase(), encoder.encode(salt + num)));
110
115
  }
116
+ export default {
117
+ createChallenge,
118
+ verifySolution,
119
+ solveChallenge,
120
+ solveChallengeWorkers,
121
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "altcha-lib",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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",