yeojz / otplib

:key: One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator

Home Page:https://otplib.yeojz.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not workign with verifyr

trajano opened this issue · comments

Describe the bug
Trying out the library with https://www.verifyr.com/en/otp/check not sure if it is a problem with the tool or the library.

To Reproduce

import { test, expect } from "@jest/globals";
import { Authenticator, HashAlgorithms, KeyEncodings } from "@otplib/core";
import { keyDecoder, keyEncoder } from "@otplib/plugin-thirty-two";
import { createDigest } from "@otplib/plugin-crypto";

test("otp", () => {
  const secret = "obtained from the server";
  const authenticator = new Authenticator({
    algorithm: HashAlgorithms.SHA1,
    digits: 6,
    epoch: 0,
    step: 30,
    keyDecoder,
    keyEncoder,
    createDigest,
  });

  const token = authenticator.generate(secret);
  console.log(token);

  const isValid = authenticator.verify({ token, secret });
  expect(isValid).toBe(true);
});

Expected behavior

The OTP code that I got printed on the console works on the verifyr website, but it fails verification

Screenshots

Details (please provide any relevant information):

  • otplib version: 12.0.1
  • os:
  • browser:
  • node / yarn:
  • frameworks (if any):

Additional context
Add any other context about the problem here.

Nix that epoch should be Date.now()