2024-11-24 01:23:54 -03:00
|
|
|
import * as OTPAuth from 'otpauth'
|
|
|
|
|
2024-11-29 17:22:29 -03:00
|
|
|
let secret = new OTPAuth.Secret({ size: 20 })
|
|
|
|
|
2024-11-24 01:23:54 -03:00
|
|
|
export const totp = () => {
|
|
|
|
let totp = new OTPAuth.TOTP({
|
|
|
|
issuer: 'Private data',
|
|
|
|
label: 'otp',
|
2024-11-29 17:22:29 -03:00
|
|
|
algorithm: 'SHA256',
|
2024-11-24 01:23:54 -03:00
|
|
|
digits: 6,
|
|
|
|
period: 300,
|
2024-11-29 17:22:29 -03:00
|
|
|
secret
|
2024-11-24 01:23:54 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
let token = totp.generate()
|
|
|
|
let seconds = totp.period - (Math.floor(Date.now() / 1000) % totp.period)
|
|
|
|
let uri = totp.toString()
|
|
|
|
|
|
|
|
return { token, seconds, uri }
|
|
|
|
}
|