Skip to main content
Latest
File
import * as OTP from 'https://deno.land/x/otpauth@v9.0.2/dist/otpauth.esm.js'
/** * @deprecated moved to the core: * * ``` * import { authenticator } from 'darkflare' * * authenticator.secret(...) * ``` */export function secret(length = 64) { return [...Array(length)].map(() => Math.floor(Math.random() * 16).toString(16) ).join('')}
/** * @deprecated moved to the core: * * ``` * import { authenticator } from 'darkflare' * * authenticator.token(...) * ``` */export function token(secret: string, timestamp?: number) { const totp = new OTP.TOTP({ algorithm: 'SHA1', digits: 6, period: 30, secret: OTP.Secret.fromHex(secret) })
return totp.generate({ timestamp })}
/** * @deprecated moved to the core: * * ``` * import { authenticator } from 'darkflare' * * authenticator.uri(...) * ``` */export function uri(label: string, issuer: string, secret: string) { const totp = new OTP.TOTP({ issuer, label, algorithm: 'SHA1', digits: 6, period: 30, secret: OTP.Secret.fromHex(secret) })
return totp.toString()}
/** * @deprecated moved to the core: * * ``` * import { authenticator } from 'darkflare' * * authenticator.validate(...) * ``` */export function validate(token: string, secret: string) { const totp = new OTP.TOTP({ algorithm: 'SHA1', digits: 6, period: 30, secret: OTP.Secret.fromHex(secret) })
return totp.validate({ token }) === 0}