fix: provided hashType into getOTP

This commit is contained in:
Pavel-Savely Savianok 2025-07-24 17:42:48 +03:00 committed by Savely Savenok
parent 56d5edc37b
commit d45be3ee68
2 changed files with 4 additions and 4 deletions

View File

@ -54,6 +54,6 @@ export function getTOTP(
timeOffset = 0,
hashType = "SHA-1",
) {
const unixTime = Math.round((time / 1000 + timeOffset) / fetchTime);
return getHOTP(BigInt(unixTime), secret, digits);
const unixTime = Math.round((time / 1000n + timeOffset) / fetchTime);
return getHOTP(BigInt(unixTime), secret, digits, hashType);
}

View File

@ -48,12 +48,12 @@ export class TOTP {
*/
getOTP(time = Date.now()) {
const unixTime = (time / 1000 + this.timeOffset) / this.fetchTime;
const otp = getHOTP(Math.floor(unixTime), this.secret, this.digits);
const otp = getHOTP(Math.floor(unixTime), this.secret, this.digits, this.hashType);
const expireTime =
time +
(this.fetchTime -
((time / 1000 + this.timeOffset) % this.fetchTime)) *
1000;
1000;
const createdTime =
time - ((time / 1000 + this.timeOffset) % this.fetchTime) * 1000;