A Time-Based (RFC 6238) and HMAC-Based (RFC 4226) One-Time Password Algorithm Implementation in TypeScript.
# Bun
bun add @deanrih/totp-ts
# pnpm
pnpm add @deanrih/totp-ts
# npm
npm install @deanrih/totp-ts
import { generateTotp } from "@deanrih/totp-ts";
const secret = "super_S3cr37-k3y";
const password = generateTotp(secret);
console.log(`Your One-time Password: [${password}]`);
import { generateTotp } from "@deanrih/totp-ts";
const secret = "super_S3cr37-k3y";
console.log(`Your One-time Password: [${generateTotp(secret)}]`);
await Bun.sleep(30 * 1000); // Wait for 30 seconds to see the new code generated
console.log(`Your One-time Password: [${generateTotp(secret)}]`);
Checkout the example folder.
IETF RFC Datatracker