altcha-lib 0.3.0 → 0.4.1
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 +16 -0
- package/cjs/dist/helpers.d.ts +0 -1
- package/cjs/dist/helpers.js +0 -2
- package/cjs/dist/index.js +1 -6
- package/dist/helpers.d.ts +0 -1
- package/dist/helpers.js +0 -2
- package/dist/index.js +1 -6
- package/package.json +1 -1
- package/cjs/dist/crypto.d.ts +0 -1
- package/cjs/dist/crypto.js +0 -6
- package/dist/crypto.d.ts +0 -1
- package/dist/crypto.js +0 -5
package/README.md
CHANGED
|
@@ -28,6 +28,22 @@ const challenge = await createChallenge({
|
|
|
28
28
|
const ok = await verifySolution(payload, hmacKey);
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
### Usage with Node.js 16
|
|
32
|
+
|
|
33
|
+
In Node.js version 16, there is no global reference to crypto by default. To use this library, you need to add the following code to your codebase:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
globalThis.crypto = require('node:crypto').webcrypto;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or with `import` syntax:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { webcrypto } from 'node:crypto';
|
|
43
|
+
|
|
44
|
+
globalThis.crypto = webcrypto;
|
|
45
|
+
```
|
|
46
|
+
|
|
31
47
|
## API
|
|
32
48
|
|
|
33
49
|
### `createChallenge(options)`
|
package/cjs/dist/helpers.d.ts
CHANGED
package/cjs/dist/helpers.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.randomInt = exports.randomBytes = exports.hmacHex = exports.hmac = exports.hashHex = exports.hash = exports.ab2hex = exports.encoder = void 0;
|
|
4
|
-
// @denoify-line-ignore
|
|
5
|
-
require("./crypto.js");
|
|
6
4
|
exports.encoder = new TextEncoder();
|
|
7
5
|
function ab2hex(ab) {
|
|
8
6
|
return [...new Uint8Array(ab)]
|
package/cjs/dist/index.js
CHANGED
|
@@ -117,12 +117,7 @@ function solveChallenge(challenge, salt, algorithm = 'SHA-256', max = 1e6, start
|
|
|
117
117
|
exports.solveChallenge = solveChallenge;
|
|
118
118
|
async function solveChallengeWorkers(workerScript, concurrency, challenge, salt, algorithm = 'SHA-256', max = 1e6, startNumber = 0) {
|
|
119
119
|
const workers = [];
|
|
120
|
-
|
|
121
|
-
throw new Error('Wrong number of workers configured.');
|
|
122
|
-
}
|
|
123
|
-
if (concurrency > 16) {
|
|
124
|
-
throw new Error('Too many workers. Max. 16 allowed workers.');
|
|
125
|
-
}
|
|
120
|
+
concurrency = Math.min(1, Math.max(16, concurrency));
|
|
126
121
|
for (let i = 0; i < concurrency; i++) {
|
|
127
122
|
if (typeof workerScript === 'function') {
|
|
128
123
|
workers.push(workerScript());
|
package/dist/helpers.d.ts
CHANGED
package/dist/helpers.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -109,12 +109,7 @@ export function solveChallenge(challenge, salt, algorithm = 'SHA-256', max = 1e6
|
|
|
109
109
|
}
|
|
110
110
|
export async function solveChallengeWorkers(workerScript, concurrency, challenge, salt, algorithm = 'SHA-256', max = 1e6, startNumber = 0) {
|
|
111
111
|
const workers = [];
|
|
112
|
-
|
|
113
|
-
throw new Error('Wrong number of workers configured.');
|
|
114
|
-
}
|
|
115
|
-
if (concurrency > 16) {
|
|
116
|
-
throw new Error('Too many workers. Max. 16 allowed workers.');
|
|
117
|
-
}
|
|
112
|
+
concurrency = Math.min(1, Math.max(16, concurrency));
|
|
118
113
|
for (let i = 0; i < concurrency; i++) {
|
|
119
114
|
if (typeof workerScript === 'function') {
|
|
120
115
|
workers.push(workerScript());
|
package/package.json
CHANGED
package/cjs/dist/crypto.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/cjs/dist/crypto.js
DELETED
package/dist/crypto.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|