@sunknudsen/totp
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@sunknudsen/totp

Generate and validate TOTP tokens.

Installation

$ npm install @sunknudsen/totp

Usage

import {
  generateSecret,
  generateUri,
  generateToken,
  validateToken,
} from "@sunknudsen/totp"

const secret = generateSecret()

console.log(secret)
// DMJKP7AU22WKWRG3DNIQ3ERA

const uri = generateUri(
  "Superbacked",
  "john@protonmail.com",
  "DMJKP7AU22WKWRG3DNIQ3ERA",
  "Superbacked"
)

console.log(uri)
// otpauth://totp/Superbacked:john%40protonmail.com?secret=DMJKP7AU22WKWRG3DNIQ3ERA&issuer=Superbacked&algorithm=SHA1&digits=6&period=30

const token = generateToken("DMJKP7AU22WKWRG3DNIQ3ERA")

console.log(token)
// 616692

const result = validateToken("DMJKP7AU22WKWRG3DNIQ3ERA", "616692")

console.log(result)
// true

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i @sunknudsen/totp

    Weekly Downloads

    10,374

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    15 kB

    Total Files

    9

    Last publish

    Collaborators

    • sunknudsen