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(otp, key, intervalInSeconds, digits);

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 uri = createTOTPKeyURI(issuer, accountName, key);
uri.setDigits(6);
uri.setPeriodInSeconds(30);