@nowarajs/totp 1.1.11 → 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/README.md CHANGED
@@ -210,6 +210,5 @@ Distributed under the MIT License. See [LICENSE](./LICENSE) for more information
210
210
 
211
211
  ## 📧 Contact
212
212
 
213
+ - Mail: [nowarajs@pm.me](mailto:nowarajs@pm.me)
213
214
  - GitHub: [NowaraJS](https://github.com/NowaraJS)
214
- - Package: [@nowarajs/totp](https://www.npmjs.com/package/@nowarajs/totp)
215
-
@@ -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 };
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  TOTP_ERROR_KEYS
4
- } from "../chunk-4z2jb9kh.js";
4
+ } from "../chunk-sx6rwmqe.js";
5
5
  export {
6
6
  TOTP_ERROR_KEYS
7
7
  };
@@ -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-4z2jb9kh.js";
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 { BaseError } from "@nowarajs/error";
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 BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
48
+ throw new InternalError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
49
49
  if (url.hostname !== "totp")
50
- throw new BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
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 BaseError(TOTP_ERROR_KEYS.MISSING_SECRET);
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";
@@ -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 BaseError}) - if the URI is invalid or missing required parameters
15
+ * @throws ({@link InternalError}) - if the URI is invalid or missing required parameters
16
16
  *
17
17
  * @returns Parsed URI parameters
18
18
  */
@@ -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 BaseError}) - if invalid Base32 character is found
15
+ * @throws ({@link InternalError}) - if invalid Base32 character is found
16
16
  *
17
17
  * @returns Decoded bytes
18
18
  */
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @param length - Number of bytes to generate (default: 20)
5
5
  *
6
- * @throws ({@link BaseError}) if length is not positive
6
+ * @throws ({@link InternalError}) if length is not positive
7
7
  *
8
8
  * @returns Uint8Array containing the random bytes
9
9
  */
@@ -6,10 +6,10 @@ import {
6
6
  } from "../chunk-q8z45f9z.js";
7
7
  import {
8
8
  TOTP_ERROR_KEYS
9
- } from "../chunk-4z2jb9kh.js";
9
+ } from "../chunk-sx6rwmqe.js";
10
10
 
11
11
  // source/utils/base32.ts
12
- import { BaseError } from "@nowarajs/error";
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 BaseError(TOTP_ERROR_KEYS.INVALID_BASE32_CHARACTER, `Invalid Base32 character: ${char}`);
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 { BaseError as BaseError2 } from "@nowarajs/error";
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 BaseError2(TOTP_ERROR_KEYS.INVALID_SECRET_LENGTH);
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.1.11",
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.38.0",
26
- "@nowarajs/error": "^1.3.7",
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.0",
29
- "eslint": "^9.38.0",
30
- "globals": "^16.4.0",
31
- "typescript-eslint": "^8.46.2",
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.7"
35
+ "@nowarajs/error": "^1.3.10"
36
36
  },
37
37
  "exports": {
38
38
  "./enums": "./dist/enums/index.js",
@@ -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 };