altcha-lib 0.1.0 → 0.1.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 +2 -0
- package/dist/index.js +6 -3
- package/dist/types.d.ts +2 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -37,8 +37,10 @@ Parameters:
|
|
|
37
37
|
- `options: ChallengeOptions`:
|
|
38
38
|
- `algorithm?: string`: Algorithm to use (`SHA-1`, `SHA-256`, `SHA-512`, default: `SHA-256`).
|
|
39
39
|
- `hmacKey: string` (required): Signature HMAC key.
|
|
40
|
+
- `maxNumber?: number` Optional maximum number for the random number generator (defaults to 1,000,000).
|
|
40
41
|
- `number?: number`: Optional number to use. If not provided, a random number will be generated.
|
|
41
42
|
- `salt?: string`: Optional salt string. If not provided, a random salt will be generated.
|
|
43
|
+
- `saltLength?: number` Optional maximum lenght of the random salt (in bytes, defaults to 12).
|
|
42
44
|
|
|
43
45
|
### `verifySolution(payload, hmacKey)`
|
|
44
46
|
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { ab2hex, hash, hmac, randomBytes, randomInt } from './helpers.js';
|
|
2
|
-
const DEFAULT_MAX_NUMBER =
|
|
2
|
+
const DEFAULT_MAX_NUMBER = 1e6;
|
|
3
|
+
const DEFAULT_SALT_LEN = 12;
|
|
3
4
|
const DEFAULT_ALG = 'SHA-256';
|
|
4
5
|
export async function createChallenge(options) {
|
|
5
6
|
const algorithm = options.algorithm || DEFAULT_ALG;
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const maxNumber = options.maxNumber || DEFAULT_MAX_NUMBER;
|
|
8
|
+
const saltLength = options.saltLength || DEFAULT_SALT_LEN;
|
|
9
|
+
const salt = options.salt || ab2hex(randomBytes(saltLength));
|
|
10
|
+
const number = options.number === void 0 ? randomInt(maxNumber) : options.number;
|
|
8
11
|
const challenge = await hash(algorithm, salt + number);
|
|
9
12
|
return {
|
|
10
13
|
algorithm,
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "altcha-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.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",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./types": {
|
|
34
|
+
"types": "./dist/types.d.ts",
|
|
35
|
+
"import": "./dist/types.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"typesVersions": {
|