@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.
- package/dist/{chunk-4qsch0ea.js → chunk-4z2jb9kh.js} +4 -3
- package/dist/{chunk-hhdy89hc.js → chunk-q8z45f9z.js} +4 -3
- package/dist/enums/index.d.ts +1 -1
- package/dist/enums/index.js +1 -1
- package/dist/hotp.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -12
- package/dist/{otpAuthUri.d.ts → otp-auth-uri.d.ts} +1 -1
- package/dist/totp.d.ts +2 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/{verifyOptions.d.ts → verify-options.d.ts} +1 -1
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.js +6 -11
- package/package.json +9 -9
- package/dist/enums/{totpErrorKeys.d.ts → totp-error-keys.d.ts} +2 -2
- /package/dist/types/{otpAuthUri.d.ts → otp-auth-uri.d.ts} +0 -0
- /package/dist/types/{totpOptions.d.ts → totp-options.d.ts} +0 -0
- /package/dist/utils/{createCounterBuffer.d.ts → create-counter-buffer.d.ts} +0 -0
- /package/dist/utils/{dynamicTruncation.d.ts → dynamic-truncation.d.ts} +0 -0
- /package/dist/utils/{generateHmac.d.ts → generate-hmac.d.ts} +0 -0
- /package/dist/utils/{generateSecretBytes.d.ts → generate-secret-bytes.d.ts} +0 -0
- /package/dist/utils/{timeRemaining.d.ts → time-remaining.d.ts} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
//
|
|
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
|
-
//
|
|
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/
|
|
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/
|
|
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);
|
package/dist/enums/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { TOTP_ERROR_KEYS } from './
|
|
1
|
+
export { TOTP_ERROR_KEYS } from './totp-error-keys';
|
package/dist/enums/index.js
CHANGED
package/dist/hotp.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
createCounterBuffer,
|
|
4
4
|
dynamicTruncation,
|
|
5
5
|
generateHmac
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-q8z45f9z.js";
|
|
7
7
|
import {
|
|
8
8
|
TOTP_ERROR_KEYS
|
|
9
|
-
} from "./chunk-
|
|
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/
|
|
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";
|
package/dist/totp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TotpOptions } from './types/
|
|
2
|
-
import type { VerifyOptions } from './types/
|
|
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
|
*
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { OtpAuthUri } from './
|
|
2
|
-
export type { TotpOptions } from './
|
|
3
|
-
export type { VerifyOptions } from './
|
|
1
|
+
export type { OtpAuthUri } from './otp-auth-uri';
|
|
2
|
+
export type { TotpOptions } from './totp-options';
|
|
3
|
+
export type { VerifyOptions } from './verify-options';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { base32Decode, base32Encode } from './base32';
|
|
2
|
-
export { createCounterBuffer } from './
|
|
3
|
-
export { dynamicTruncation } from './
|
|
4
|
-
export { generateHmac } from './
|
|
5
|
-
export { generateSecretBytes } from './
|
|
6
|
-
export { timeRemaining } from './
|
|
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';
|
package/dist/utils/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
createCounterBuffer,
|
|
4
4
|
dynamicTruncation,
|
|
5
5
|
generateHmac
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-q8z45f9z.js";
|
|
7
7
|
import {
|
|
8
8
|
TOTP_ERROR_KEYS
|
|
9
|
-
} from "../chunk-
|
|
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/
|
|
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/
|
|
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.
|
|
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.
|
|
26
|
-
"@nowarajs/error": "^1.1
|
|
27
|
-
"@stylistic/eslint-plugin": "^5.
|
|
28
|
-
"@types/bun": "^1.2.
|
|
29
|
-
"eslint": "^9.
|
|
30
|
-
"globals": "^16.
|
|
31
|
-
"typescript-eslint": "^8.
|
|
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
|
|
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
|
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|