@nowarajs/totp 1.1.12 → 1.2.0
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/chunk-sx6rwmqe.js +11 -0
- package/dist/enums/index.js +1 -1
- package/dist/enums/totp-error-keys.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/otp-auth-uri.d.ts +1 -1
- package/dist/utils/base32.d.ts +1 -1
- package/dist/utils/generate-secret-bytes.d.ts +1 -1
- package/dist/utils/index.js +5 -5
- package/package.json +8 -8
- package/dist/chunk-4z2jb9kh.js +0 -11
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/enums/totp-error-keys.ts
|
|
3
|
+
var TOTP_ERROR_KEYS = {
|
|
4
|
+
INVALID_ALGORITHM: "nowarajs.totp.error.invalid_algorithm",
|
|
5
|
+
INVALID_BASE32_CHARACTER: "nowarajs.totp.error.invalid_base32_character",
|
|
6
|
+
INVALID_OTP_AUTH_URI: "nowarajs.totp.error.invalid_otp_auth_uri",
|
|
7
|
+
INVALID_SECRET_LENGTH: "nowarajs.totp.error.invalid_secret_length",
|
|
8
|
+
MISSING_SECRET: "nowarajs.totp.error.missing_secret"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { TOTP_ERROR_KEYS };
|
package/dist/enums/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const TOTP_ERROR_KEYS: {
|
|
2
|
-
readonly INVALID_ALGORITHM: "totp.error.invalid_algorithm";
|
|
3
|
-
readonly INVALID_BASE32_CHARACTER: "totp.error.invalid_base32_character";
|
|
4
|
-
readonly INVALID_OTP_AUTH_URI: "totp.error.invalid_otp_auth_uri";
|
|
5
|
-
readonly INVALID_SECRET_LENGTH: "totp.error.invalid_secret_length";
|
|
6
|
-
readonly MISSING_SECRET: "totp.error.missing_secret";
|
|
2
|
+
readonly INVALID_ALGORITHM: "nowarajs.totp.error.invalid_algorithm";
|
|
3
|
+
readonly INVALID_BASE32_CHARACTER: "nowarajs.totp.error.invalid_base32_character";
|
|
4
|
+
readonly INVALID_OTP_AUTH_URI: "nowarajs.totp.error.invalid_otp_auth_uri";
|
|
5
|
+
readonly INVALID_SECRET_LENGTH: "nowarajs.totp.error.invalid_secret_length";
|
|
6
|
+
readonly MISSING_SECRET: "nowarajs.totp.error.missing_secret";
|
|
7
7
|
};
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-q8z45f9z.js";
|
|
7
7
|
import {
|
|
8
8
|
TOTP_ERROR_KEYS
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-sx6rwmqe.js";
|
|
10
10
|
|
|
11
11
|
// source/hotp.ts
|
|
12
12
|
import { webcrypto } from "crypto";
|
|
@@ -20,7 +20,7 @@ var hotp = async (secret, counter, {
|
|
|
20
20
|
return dynamicTruncation(hmacArray, digits);
|
|
21
21
|
};
|
|
22
22
|
// source/otp-auth-uri.ts
|
|
23
|
-
import {
|
|
23
|
+
import { InternalError } from "@nowarajs/error";
|
|
24
24
|
var buildOtpAuthUri = ({
|
|
25
25
|
secretBase32,
|
|
26
26
|
label,
|
|
@@ -45,13 +45,13 @@ var buildOtpAuthUri = ({
|
|
|
45
45
|
var parseOtpAuthUri = (uri) => {
|
|
46
46
|
const url = new URL(uri);
|
|
47
47
|
if (url.protocol !== "otpauth:")
|
|
48
|
-
throw new
|
|
48
|
+
throw new InternalError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
|
|
49
49
|
if (url.hostname !== "totp")
|
|
50
|
-
throw new
|
|
50
|
+
throw new InternalError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
|
|
51
51
|
const label = decodeURIComponent(url.pathname.slice(1));
|
|
52
52
|
const secretBase32 = url.searchParams.get("secret");
|
|
53
53
|
if (!secretBase32)
|
|
54
|
-
throw new
|
|
54
|
+
throw new InternalError(TOTP_ERROR_KEYS.MISSING_SECRET);
|
|
55
55
|
const issuerParam = url.searchParams.get("issuer");
|
|
56
56
|
const issuer = issuerParam ? decodeURIComponent(issuerParam) : undefined;
|
|
57
57
|
const algorithm = url.searchParams.get("algorithm") || "SHA-1";
|
package/dist/otp-auth-uri.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const buildOtpAuthUri: ({ secretBase32, label, issuer, algorithm,
|
|
|
12
12
|
*
|
|
13
13
|
* @param uri - OTPAuth URI to parse
|
|
14
14
|
*
|
|
15
|
-
* @throws ({@link
|
|
15
|
+
* @throws ({@link InternalError}) - if the URI is invalid or missing required parameters
|
|
16
16
|
*
|
|
17
17
|
* @returns Parsed URI parameters
|
|
18
18
|
*/
|
package/dist/utils/base32.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const base32Encode: (input: string | Uint8Array, withPadding?: bo
|
|
|
12
12
|
*
|
|
13
13
|
* @param base32 - Base32 string to decode
|
|
14
14
|
*
|
|
15
|
-
* @throws ({@link
|
|
15
|
+
* @throws ({@link InternalError}) - if invalid Base32 character is found
|
|
16
16
|
*
|
|
17
17
|
* @returns Decoded bytes
|
|
18
18
|
*/
|
package/dist/utils/index.js
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
} from "../chunk-q8z45f9z.js";
|
|
7
7
|
import {
|
|
8
8
|
TOTP_ERROR_KEYS
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-sx6rwmqe.js";
|
|
10
10
|
|
|
11
11
|
// source/utils/base32.ts
|
|
12
|
-
import {
|
|
12
|
+
import { InternalError } from "@nowarajs/error";
|
|
13
13
|
var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
14
14
|
var base32Encode = (input, withPadding = true) => {
|
|
15
15
|
let result = "";
|
|
@@ -41,7 +41,7 @@ var base32Decode = (base32) => {
|
|
|
41
41
|
for (const char of cleanBase32) {
|
|
42
42
|
const charValue = BASE32_ALPHABET.indexOf(char);
|
|
43
43
|
if (charValue === -1)
|
|
44
|
-
throw new
|
|
44
|
+
throw new InternalError(TOTP_ERROR_KEYS.INVALID_BASE32_CHARACTER, `Invalid Base32 character: ${char}`);
|
|
45
45
|
value = value << 5 | charValue;
|
|
46
46
|
bits += 5;
|
|
47
47
|
if (bits >= 8) {
|
|
@@ -52,11 +52,11 @@ var base32Decode = (base32) => {
|
|
|
52
52
|
return new Uint8Array(result);
|
|
53
53
|
};
|
|
54
54
|
// source/utils/generate-secret-bytes.ts
|
|
55
|
-
import {
|
|
55
|
+
import { InternalError as InternalError2 } from "@nowarajs/error";
|
|
56
56
|
import { getRandomValues } from "crypto";
|
|
57
57
|
var generateSecretBytes = (length = 20) => {
|
|
58
58
|
if (length <= 0)
|
|
59
|
-
throw new
|
|
59
|
+
throw new InternalError2(TOTP_ERROR_KEYS.INVALID_SECRET_LENGTH);
|
|
60
60
|
return getRandomValues(new Uint8Array(length));
|
|
61
61
|
};
|
|
62
62
|
// source/utils/time-remaining.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nowarajs/totp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"author": "NowaraJS",
|
|
5
5
|
"description": "A comprehensive Time-based One-Time Password (TOTP) and HMAC-based One-Time Password (HOTP)",
|
|
6
6
|
"type": "module",
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"test": "bun test --coverage"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@eslint/js": "^9.
|
|
26
|
-
"@nowarajs/error": "^1.3.
|
|
25
|
+
"@eslint/js": "^9.39.1",
|
|
26
|
+
"@nowarajs/error": "^1.3.10",
|
|
27
27
|
"@stylistic/eslint-plugin": "^5.5.0",
|
|
28
|
-
"@types/bun": "^1.3.
|
|
29
|
-
"eslint": "^9.
|
|
30
|
-
"globals": "^16.
|
|
31
|
-
"typescript-eslint": "^8.46.
|
|
28
|
+
"@types/bun": "^1.3.2",
|
|
29
|
+
"eslint": "^9.39.1",
|
|
30
|
+
"globals": "^16.5.0",
|
|
31
|
+
"typescript-eslint": "^8.46.4",
|
|
32
32
|
"typescript": "^5.9.3"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@nowarajs/error": "^1.3.
|
|
35
|
+
"@nowarajs/error": "^1.3.10"
|
|
36
36
|
},
|
|
37
37
|
"exports": {
|
|
38
38
|
"./enums": "./dist/enums/index.js",
|
package/dist/chunk-4z2jb9kh.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// source/enums/totp-error-keys.ts
|
|
3
|
-
var TOTP_ERROR_KEYS = {
|
|
4
|
-
INVALID_ALGORITHM: "totp.error.invalid_algorithm",
|
|
5
|
-
INVALID_BASE32_CHARACTER: "totp.error.invalid_base32_character",
|
|
6
|
-
INVALID_OTP_AUTH_URI: "totp.error.invalid_otp_auth_uri",
|
|
7
|
-
INVALID_SECRET_LENGTH: "totp.error.invalid_secret_length",
|
|
8
|
-
MISSING_SECRET: "totp.error.missing_secret"
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { TOTP_ERROR_KEYS };
|