This commit is contained in:
“xHuPo” 2025-06-17 14:44:48 +08:00
parent 17a02ea47e
commit 70e7a113e6
22 changed files with 967 additions and 285 deletions

View file

@ -3,7 +3,7 @@ const { decode: base32Decode } = require('./base32.js');
const { constantTimeEqual, safeIntegerParse } = require('./crypto.js');
// 支持的哈希算法
const HASH_ALGOS = {
const HASH_ALGORITHMS = {
'SHA1': 'SHA1',
'SHA256': 'SHA256',
'SHA512': 'SHA512'
@ -11,7 +11,7 @@ const HASH_ALGOS = {
// 默认配置
const DEFAULT_CONFIG = {
algorithm: HASH_ALGOS.SHA1, // 默认使用SHA1
algorithm: HASH_ALGORITHMS.SHA1, // 默认使用SHA1
period: 30, // 默认30秒时间窗口
digits: 6, // 默认6位数字
timestamp: null, // 默认使用当前时间
@ -40,7 +40,7 @@ async function generateTOTP(secret, options = {}) {
const config = { ...DEFAULT_CONFIG, ...options };
// 验证算法
if (!HASH_ALGOS[config.algorithm]) {
if (!HASH_ALGORITHMS[config.algorithm]) {
throw new Error(`Unsupported algorithm: ${config.algorithm}`);
}
@ -219,7 +219,7 @@ function generateTOTPUri(secret, accountName, issuer, options = {}) {
const config = { ...DEFAULT_CONFIG, ...options };
// 验证算法
if (!HASH_ALGOS[config.algorithm]) {
if (!HASH_ALGORITHMS[config.algorithm]) {
throw new Error(`Unsupported algorithm: ${config.algorithm}`);
}
@ -255,5 +255,5 @@ module.exports = {
verifyTOTP,
getRemainingSeconds,
generateTOTPUri,
HASH_ALGOS
HASH_ALGORITHMS
};