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 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)`
@@ -1,4 +1,3 @@
1
- import './crypto.js';
2
1
  import type { Algorithm } from './types.js';
3
2
  export declare const encoder: TextEncoder;
4
3
  export declare function ab2hex(ab: ArrayBuffer | Uint8Array): string;
@@ -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
- if (concurrency < 1) {
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
@@ -1,4 +1,3 @@
1
- import './crypto.js';
2
1
  import type { Algorithm } from './types.js';
3
2
  export declare const encoder: TextEncoder;
4
3
  export declare function ab2hex(ab: ArrayBuffer | Uint8Array): string;
package/dist/helpers.js CHANGED
@@ -1,5 +1,3 @@
1
- // @denoify-line-ignore
2
- import './crypto.js';
3
1
  export const encoder = new TextEncoder();
4
2
  export function ab2hex(ab) {
5
3
  return [...new Uint8Array(ab)]
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
- if (concurrency < 1) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "altcha-lib",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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",
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- if (!('crypto' in globalThis)) {
4
- // eslint-disable-next-line @typescript-eslint/no-var-requires
5
- globalThis.crypto = require('node:crypto').webcrypto;
6
- }
package/dist/crypto.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/crypto.js DELETED
@@ -1,5 +0,0 @@
1
- if (!('crypto' in globalThis)) {
2
- // eslint-disable-next-line @typescript-eslint/no-var-requires
3
- globalThis.crypto = require('node:crypto').webcrypto;
4
- }
5
- export {};