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.
- package/cjs/dist/index.d.ts +8 -1
- package/cjs/dist/index.js +14 -3
- package/dist/index.d.ts +8 -1
- package/dist/index.js +14 -3
- package/package.json +1 -1
package/cjs/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/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
|
-
|
|
80
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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
|
+
};
|