Time-based one-time passwords
Use generateTOTP()
and verifyTOTP()
to generate and verify HOTPs.
import { generateTOTP, verifyTOTP } from "@oslojs/otp";
const digits = 6;
const intervalInSeconds = 30;
const otp = generateTOTP(key, intervalInSeconds, digits);
const validOTP = verifyTOTP(key, intervalInSeconds, digits, otp);
Use createTOTPKeyURI()
to create a key URI, which are then usually encoded into a QR code.
import { createTOTPKeyURI } from "@oslojs/otp";
const issuer = "My app";
const accountName = "[email protected]";
const intervalInSeconds = 30;
const digits = 6;
const uri = createTOTPKeyURI(issuer, accountName, key, intervalInSeconds, digits);