@nowarajs/totp 1.2.2 → 1.2.4
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/dist/index.js +7 -9
- package/package.json +27 -26
package/dist/index.js
CHANGED
|
@@ -28,17 +28,15 @@ var _getCryptoKey = async (secret, algorithm) => {
|
|
|
28
28
|
if (firstKey)
|
|
29
29
|
_keyCache.delete(firstKey);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const keyData = new Uint8Array(secret);
|
|
32
|
+
const key = await webcrypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: algorithm }, false, ["sign"]);
|
|
32
33
|
_keyCache.set(cacheKey, key);
|
|
33
34
|
return key;
|
|
34
35
|
};
|
|
35
36
|
var clearKeyCache = () => {
|
|
36
37
|
_keyCache.clear();
|
|
37
38
|
};
|
|
38
|
-
var hotp = async (secret, counter, {
|
|
39
|
-
algorithm = "SHA-1",
|
|
40
|
-
digits = 6
|
|
41
|
-
} = {}) => {
|
|
39
|
+
var hotp = async (secret, counter, { algorithm = "SHA-1", digits = 6 } = {}) => {
|
|
42
40
|
if (secret.length < 16)
|
|
43
41
|
throw new InternalError(TOTP_ERROR_KEYS.WEAK_SECRET, "Secret must be at least 16 bytes (128 bits)");
|
|
44
42
|
const counterBuffer = createCounterBuffer(counter);
|
|
@@ -83,15 +81,15 @@ var parseOtpAuthUri = (uri) => {
|
|
|
83
81
|
throw new InternalError2(TOTP_ERROR_KEYS.MISSING_SECRET, "Secret is required");
|
|
84
82
|
const issuerParam = url.searchParams.get("issuer");
|
|
85
83
|
const issuer = issuerParam ? decodeURIComponent(issuerParam) : undefined;
|
|
86
|
-
const algorithmParam = url.searchParams.get("algorithm")
|
|
84
|
+
const algorithmParam = url.searchParams.get("algorithm") ?? "SHA-1";
|
|
87
85
|
if (algorithmParam !== "SHA-1" && algorithmParam !== "SHA-256" && algorithmParam !== "SHA-512")
|
|
88
86
|
throw new InternalError2(TOTP_ERROR_KEYS.INVALID_ALGORITHM, "Algorithm must be SHA-1, SHA-256, or SHA-512");
|
|
89
87
|
const algorithm = algorithmParam;
|
|
90
|
-
const digitsParam = parseInt(url.searchParams.get("digits")
|
|
88
|
+
const digitsParam = parseInt(url.searchParams.get("digits") ?? "6", 10);
|
|
91
89
|
if (digitsParam !== 6 && digitsParam !== 8)
|
|
92
90
|
throw new InternalError2(TOTP_ERROR_KEYS.INVALID_DIGITS, "Digits must be 6 or 8");
|
|
93
91
|
const digits = digitsParam;
|
|
94
|
-
const period = parseInt(url.searchParams.get("period")
|
|
92
|
+
const period = parseInt(url.searchParams.get("period") ?? "30", 10);
|
|
95
93
|
if (!Number.isFinite(period) || period <= 0)
|
|
96
94
|
throw new InternalError2(TOTP_ERROR_KEYS.INVALID_PERIOD, "Period must be a positive integer");
|
|
97
95
|
const result = {
|
|
@@ -107,7 +105,7 @@ var parseOtpAuthUri = (uri) => {
|
|
|
107
105
|
// source/totp.ts
|
|
108
106
|
import { timingSafeEqual } from "crypto";
|
|
109
107
|
import { InternalError as InternalError3 } from "@nowarajs/error";
|
|
110
|
-
var totp =
|
|
108
|
+
var totp = (secret, {
|
|
111
109
|
algorithm = "SHA-1",
|
|
112
110
|
digits = 6,
|
|
113
111
|
period = 30,
|
package/package.json
CHANGED
|
@@ -1,44 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nowarajs/totp",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"author": "NowaraJS",
|
|
3
|
+
"version": "1.2.4",
|
|
5
4
|
"description": "A comprehensive Time-based One-Time Password (TOTP) and HMAC-based One-Time Password (HOTP)",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"license": "MIT",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"bun",
|
|
7
|
+
"hotp",
|
|
10
8
|
"nowarajs",
|
|
11
|
-
"totp"
|
|
12
|
-
"hotp"
|
|
9
|
+
"totp"
|
|
13
10
|
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "NowaraJS",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/NowaraJS/totp.git"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
"./enums": "./dist/enums/index.js",
|
|
20
|
+
"./types": "./dist/types/index.js",
|
|
21
|
+
"./utils": "./dist/utils/index.js",
|
|
22
|
+
".": "./dist/index.js"
|
|
23
|
+
},
|
|
14
24
|
"scripts": {
|
|
15
25
|
"build": "bun builder.ts",
|
|
16
26
|
"dev": "bun --watch sandbox/index.ts",
|
|
17
27
|
"docs": "bunx typedoc --tsconfig tsconfig.build.json",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
28
|
+
"fmt:check": "oxfmt --check",
|
|
29
|
+
"fmt": "oxfmt",
|
|
30
|
+
"lint:fix": "oxlint --type-aware --type-check --fix ./source",
|
|
31
|
+
"lint:github": "oxlint --type-aware --type-check --format=github ./source",
|
|
32
|
+
"lint": "oxlint --type-aware --type-check ./source",
|
|
20
33
|
"test:integration": "bun test $(find test/integration -name '*.spec.ts')",
|
|
21
34
|
"test:unit": "bun test --coverage $(find test/unit -name '*.spec.ts')",
|
|
22
35
|
"test": "bun test --coverage"
|
|
23
36
|
},
|
|
24
37
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"globals": "^17.0.0",
|
|
31
|
-
"typescript-eslint": "^8.52.0",
|
|
38
|
+
"@nowarajs/error": "^1.4.3",
|
|
39
|
+
"@types/bun": "^1.3.7",
|
|
40
|
+
"oxfmt": "^0.27.0",
|
|
41
|
+
"oxlint": "^1.42.0",
|
|
42
|
+
"oxlint-tsgolint": "^0.11.3",
|
|
32
43
|
"typescript": "^5.9.3"
|
|
33
44
|
},
|
|
34
45
|
"peerDependencies": {
|
|
35
|
-
"@nowarajs/error": "^1.4.
|
|
36
|
-
},
|
|
37
|
-
"exports": {
|
|
38
|
-
"./enums": "./dist/enums/index.js",
|
|
39
|
-
"./types": "./dist/types/index.js",
|
|
40
|
-
"./utils": "./dist/utils/index.js",
|
|
41
|
-
".": "./dist/index.js"
|
|
46
|
+
"@nowarajs/error": "^1.4.3"
|
|
42
47
|
},
|
|
43
48
|
"changelog": {
|
|
44
49
|
"types": {
|
|
@@ -96,9 +101,5 @@
|
|
|
96
101
|
"tagMessage": "v{{newVersion}}",
|
|
97
102
|
"tagBody": "v{{newVersion}}"
|
|
98
103
|
}
|
|
99
|
-
},
|
|
100
|
-
"repository": {
|
|
101
|
-
"type": "git",
|
|
102
|
-
"url": "https://github.com/NowaraJS/totp.git"
|
|
103
104
|
}
|
|
104
105
|
}
|