@nowarajs/totp 1.1.5 → 1.1.7

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.
@@ -1,9 +1,10 @@
1
- // source/enums/totpErrorKeys.ts
1
+ // @bun
2
+ // source/enums/totp-error-keys.ts
2
3
  var TOTP_ERROR_KEYS = {
3
- INVALID_BASE32_CHARACTER: "totp.error.invalid_base32_character",
4
- INVALID_SECRET_LENGTH: "totp.error.invalid_secret_length",
5
4
  INVALID_ALGORITHM: "totp.error.invalid_algorithm",
5
+ INVALID_BASE32_CHARACTER: "totp.error.invalid_base32_character",
6
6
  INVALID_OTP_AUTH_URI: "totp.error.invalid_otp_auth_uri",
7
+ INVALID_SECRET_LENGTH: "totp.error.invalid_secret_length",
7
8
  MISSING_SECRET: "totp.error.missing_secret"
8
9
  };
9
10
 
@@ -1,4 +1,5 @@
1
- // source/utils/createCounterBuffer.ts
1
+ // @bun
2
+ // source/utils/create-counter-buffer.ts
2
3
  var createCounterBuffer = (counter) => {
3
4
  const counterBuffer = new ArrayBuffer(8);
4
5
  const counterView = new DataView(counterBuffer);
@@ -9,14 +10,14 @@ var createCounterBuffer = (counter) => {
9
10
  return counterBuffer;
10
11
  };
11
12
 
12
- // source/utils/dynamicTruncation.ts
13
+ // source/utils/dynamic-truncation.ts
13
14
  var dynamicTruncation = (hmacArray, digits) => {
14
15
  const offset = hmacArray[hmacArray.length - 1] & 15;
15
16
  const code = ((hmacArray[offset] & 127) << 24 | (hmacArray[offset + 1] & 255) << 16 | (hmacArray[offset + 2] & 255) << 8 | hmacArray[offset + 3] & 255) % 10 ** digits;
16
17
  return code.toString().padStart(digits, "0");
17
18
  };
18
19
 
19
- // source/utils/generateHmac.ts
20
+ // source/utils/generate-hmac.ts
20
21
  import { webcrypto } from "crypto";
21
22
  var generateHmac = async (key, data) => {
22
23
  const hmac = await webcrypto.subtle.sign("HMAC", key, data);
@@ -1 +1 @@
1
- export { TOTP_ERROR_KEYS } from './totpErrorKeys';
1
+ export { TOTP_ERROR_KEYS } from './totp-error-keys';
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  TOTP_ERROR_KEYS
4
- } from "../chunk-4qsch0ea.js";
4
+ } from "../chunk-4z2jb9kh.js";
5
5
  export {
6
6
  TOTP_ERROR_KEYS
7
7
  };
package/dist/hotp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { TotpOptions } from './types/totpOptions';
1
+ import type { TotpOptions } from './types/totp-options';
2
2
  /**
3
3
  * HMAC-based One-Time Password (HOTP) implementation
4
4
  *
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { hotp } from './hotp';
2
- export { buildOtpAuthUri, parseOtpAuthUri } from './otpAuthUri';
2
+ export { buildOtpAuthUri, parseOtpAuthUri } from './otp-auth-uri';
3
3
  export { totp, verifyTotp } from './totp';
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@ import {
3
3
  createCounterBuffer,
4
4
  dynamicTruncation,
5
5
  generateHmac
6
- } from "./chunk-hhdy89hc.js";
6
+ } from "./chunk-q8z45f9z.js";
7
7
  import {
8
8
  TOTP_ERROR_KEYS
9
- } from "./chunk-4qsch0ea.js";
9
+ } from "./chunk-4z2jb9kh.js";
10
10
 
11
11
  // source/hotp.ts
12
12
  import { webcrypto } from "crypto";
@@ -19,7 +19,7 @@ var hotp = async (secret, counter, {
19
19
  const hmacArray = await generateHmac(key, counterBuffer);
20
20
  return dynamicTruncation(hmacArray, digits);
21
21
  };
22
- // source/otpAuthUri.ts
22
+ // source/otp-auth-uri.ts
23
23
  import { BaseError } from "@nowarajs/error";
24
24
  var buildOtpAuthUri = ({
25
25
  secretBase32,
@@ -45,19 +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({
49
- message: TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI
50
- });
48
+ throw new BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
51
49
  if (url.hostname !== "totp")
52
- throw new BaseError({
53
- message: TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI
54
- });
50
+ throw new BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
55
51
  const label = decodeURIComponent(url.pathname.slice(1));
56
52
  const secretBase32 = url.searchParams.get("secret");
57
53
  if (!secretBase32)
58
- throw new BaseError({
59
- message: TOTP_ERROR_KEYS.MISSING_SECRET
60
- });
54
+ throw new BaseError(TOTP_ERROR_KEYS.MISSING_SECRET);
61
55
  const issuerParam = url.searchParams.get("issuer");
62
56
  const issuer = issuerParam ? decodeURIComponent(issuerParam) : undefined;
63
57
  const algorithm = url.searchParams.get("algorithm") || "SHA-1";
@@ -1,4 +1,4 @@
1
- import type { OtpAuthUri } from './types/otpAuthUri';
1
+ import type { OtpAuthUri } from './types/otp-auth-uri';
2
2
  /**
3
3
  * Build an OTPAuth URI for QR code generation
4
4
  *
package/dist/totp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { TotpOptions } from './types/totpOptions';
2
- import type { VerifyOptions } from './types/verifyOptions';
1
+ import type { TotpOptions } from './types/totp-options';
2
+ import type { VerifyOptions } from './types/verify-options';
3
3
  /**
4
4
  * Time-based One-Time Password (TOTP) implementation
5
5
  *
@@ -1,3 +1,3 @@
1
- export type { OtpAuthUri } from './otpAuthUri';
2
- export type { TotpOptions } from './totpOptions';
3
- export type { VerifyOptions } from './verifyOptions';
1
+ export type { OtpAuthUri } from './otp-auth-uri';
2
+ export type { TotpOptions } from './totp-options';
3
+ export type { VerifyOptions } from './verify-options';
@@ -1,4 +1,4 @@
1
- import type { TotpOptions } from './totpOptions';
1
+ import type { TotpOptions } from './totp-options';
2
2
  /**
3
3
  * Options for TOTP verification
4
4
  */
@@ -1,6 +1,6 @@
1
1
  export { base32Decode, base32Encode } from './base32';
2
- export { createCounterBuffer } from './createCounterBuffer';
3
- export { dynamicTruncation } from './dynamicTruncation';
4
- export { generateHmac } from './generateHmac';
5
- export { generateSecretBytes } from './generateSecretBytes';
6
- export { timeRemaining } from './timeRemaining';
2
+ export { createCounterBuffer } from './create-counter-buffer';
3
+ export { dynamicTruncation } from './dynamic-truncation';
4
+ export { generateHmac } from './generate-hmac';
5
+ export { generateSecretBytes } from './generate-secret-bytes';
6
+ export { timeRemaining } from './time-remaining';
@@ -3,10 +3,10 @@ import {
3
3
  createCounterBuffer,
4
4
  dynamicTruncation,
5
5
  generateHmac
6
- } from "../chunk-hhdy89hc.js";
6
+ } from "../chunk-q8z45f9z.js";
7
7
  import {
8
8
  TOTP_ERROR_KEYS
9
- } from "../chunk-4qsch0ea.js";
9
+ } from "../chunk-4z2jb9kh.js";
10
10
 
11
11
  // source/utils/base32.ts
12
12
  import { BaseError } from "@nowarajs/error";
@@ -41,10 +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({
45
- message: TOTP_ERROR_KEYS.INVALID_BASE32_CHARACTER,
46
- cause: `Invalid Base32 character: ${char}`
47
- });
44
+ throw new BaseError(TOTP_ERROR_KEYS.INVALID_BASE32_CHARACTER, `Invalid Base32 character: ${char}`);
48
45
  value = value << 5 | charValue;
49
46
  bits += 5;
50
47
  if (bits >= 8) {
@@ -54,17 +51,15 @@ var base32Decode = (base32) => {
54
51
  }
55
52
  return new Uint8Array(result);
56
53
  };
57
- // source/utils/generateSecretBytes.ts
54
+ // source/utils/generate-secret-bytes.ts
58
55
  import { BaseError as BaseError2 } from "@nowarajs/error";
59
56
  import { getRandomValues } from "crypto";
60
57
  var generateSecretBytes = (length = 20) => {
61
58
  if (length <= 0)
62
- throw new BaseError2({
63
- message: TOTP_ERROR_KEYS.INVALID_SECRET_LENGTH
64
- });
59
+ throw new BaseError2(TOTP_ERROR_KEYS.INVALID_SECRET_LENGTH);
65
60
  return getRandomValues(new Uint8Array(length));
66
61
  };
67
- // source/utils/timeRemaining.ts
62
+ // source/utils/time-remaining.ts
68
63
  var timeRemaining = (period = 30, now = Date.now()) => {
69
64
  const elapsed = Math.floor(now / 1000) % period;
70
65
  return period - elapsed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nowarajs/totp",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
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.34.0",
26
- "@nowarajs/error": "^1.1.9",
27
- "@stylistic/eslint-plugin": "^5.2.3",
28
- "@types/bun": "^1.2.21",
29
- "eslint": "^9.34.0",
30
- "globals": "^16.3.0",
31
- "typescript-eslint": "^8.41.0",
25
+ "@eslint/js": "^9.35.0",
26
+ "@nowarajs/error": "^1.3.1",
27
+ "@stylistic/eslint-plugin": "^5.3.1",
28
+ "@types/bun": "^1.2.22",
29
+ "eslint": "^9.35.0",
30
+ "globals": "^16.4.0",
31
+ "typescript-eslint": "^8.43.0",
32
32
  "typescript": "^5.9.2"
33
33
  },
34
34
  "peerDependencies": {
35
- "@nowarajs/error": "^1.1.8"
35
+ "@nowarajs/error": "^1.3.1"
36
36
  },
37
37
  "exports": {
38
38
  "./enums": "./dist/enums/index.js",
@@ -1,7 +1,7 @@
1
1
  export declare const TOTP_ERROR_KEYS: {
2
- readonly INVALID_BASE32_CHARACTER: "totp.error.invalid_base32_character";
3
- readonly INVALID_SECRET_LENGTH: "totp.error.invalid_secret_length";
4
2
  readonly INVALID_ALGORITHM: "totp.error.invalid_algorithm";
3
+ readonly INVALID_BASE32_CHARACTER: "totp.error.invalid_base32_character";
5
4
  readonly INVALID_OTP_AUTH_URI: "totp.error.invalid_otp_auth_uri";
5
+ readonly INVALID_SECRET_LENGTH: "totp.error.invalid_secret_length";
6
6
  readonly MISSING_SECRET: "totp.error.missing_secret";
7
7
  };