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 { 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
digits: 6, // 默认6位数字
window: 1 // 默认验证前后1个计数值
};
@ -42,7 +42,7 @@ async function generateHOTP(secret, counter, options = {}) {
const config = { ...DEFAULT_CONFIG, ...options };
// 验证算法
if (!HASH_ALGOS[config.algorithm]) {
if (!HASH_ALGORITHMS[config.algorithm]) {
throw new Error(`Unsupported algorithm: ${config.algorithm}`);
}
@ -180,7 +180,7 @@ function generateHOTPUri(secret, accountName, issuer, counter, options = {}) {
const config = { ...DEFAULT_CONFIG, ...options };
// 验证算法
if (!HASH_ALGOS[config.algorithm]) {
if (!HASH_ALGORITHMS[config.algorithm]) {
throw new Error(`Unsupported algorithm: ${config.algorithm}`);
}
@ -209,5 +209,5 @@ module.exports = {
generateHOTP,
verifyHOTP,
generateHOTPUri,
HASH_ALGOS
HASH_ALGORITHMS
};